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

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.

主站蜘蛛池模板: 南宁市| 大洼县| 报价| 五台县| 神池县| 四川省| 新密市| 延吉市| 裕民县| 南丰县| 游戏| 日照市| 泗水县| 临桂县| 鸡东县| 区。| 五华县| 太湖县| 景东| 襄城县| 唐河县| 迁安市| 射洪县| 云南省| 化州市| 玛曲县| 阿瓦提县| 遵义县| 武安市| 亳州市| 京山县| 禄丰县| 韩城市| 永靖县| 金山区| 顺昌县| 台江县| 昂仁县| 江城| 临夏县| 牙克石市|