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

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.

主站蜘蛛池模板: 双流县| 长垣县| 无锡市| 喜德县| 仁寿县| 清苑县| 盖州市| 永州市| 五峰| 霍州市| 清丰县| 清水县| 迁安市| 青铜峡市| 都安| 丁青县| 温泉县| 邵阳市| 镇江市| 屏山县| 林西县| 威海市| 益阳市| 吴旗县| 汉沽区| 许昌县| 广饶县| 威海市| 中阳县| 清远市| 舞阳县| 兴化市| 乐都县| 比如县| 南丹县| 新蔡县| 如皋市| 谢通门县| 兴仁县| 公主岭市| 邮箱|