官术网_书友最值得收藏!

Shaping and structuring data

Preparing data for its end use often requires both structuring and organizing the data in the correct manner. 

To illustrate this, suppose you have a hierarchical dataset of city populations, as shown in Figure 01:

Figure 01: Hierarchical structure of the population of cities

If the goal is to create a histogram of city populations, the previous data format would be hard to work with. Not only is the information of the city populations nested within the data structure, but it is nested to varying degrees of depth. For the purposes of creating a histogram, it is better to represent the data as a list of numbers, as shown in Figure 02:

Figure 02: List of populations for histogram visualization

Making structural changes like this for large datasets requires you to build programs that can extract the data from one format and put it into another format. Shaping data is an important part of data wrangling because it ensures that the data is compatible with its intended use. In Chapter 4Reading, Exploring, and Modifying Data - Part II, I will walk through exercises to convert between data formats.

Changing the form of data does not necessarily need to involve changing its structure. Changing the form of a dataset can involve filtering the data entries, reducing the data by category, changing the order of the rows, and changing the way columns are set up.

All of the previously mentioned tasks are features of the dplyr package for R. In Chapter 7, Simplifying Data Manipulation with dplyr, I will show how to use dplyr to easily and intuitively manipulate data.

主站蜘蛛池模板: 筠连县| 武强县| 台北市| 蒲城县| 富阳市| 白朗县| 隆林| 奉贤区| 永丰县| 军事| 改则县| 剑川县| 绵竹市| 高唐县| 乐业县| 惠来县| 类乌齐县| 东乡族自治县| 阿尔山市| 临沂市| 随州市| 西城区| 英超| 金山区| 白朗县| 汶上县| 龙南县| 永昌县| 汉寿县| 山西省| 施甸县| 新乡市| 甘肃省| 隆尧县| 宾川县| 丽水市| 长兴县| 高阳县| 佛冈县| 镇沅| 耒阳市|