Tidyr package: Replacement of reshape2, more pure Function
R defines clean data as: The data of each variable is stored in its own column, and the data of each observed value is stored in its own row. Clean data is the basis for data re-processing.
Consider the example of this series 04. For melt, tidyr usesGather.
1
|
Table1 <-gather (table2, road level, average daily coverage, one_of (C ("high-speed coverage", "expressway coverage", "Main Road coverage ")))
|
The last parameter specifies the columns to be gather. X: Y indicates the columns from X to Y, and-Z indicates that the columns do not include Z. You can also use the select option expression of the dplyr package to select columns. The example code uses the one_of expression.
For cast and tidyrSpread.
1
|
Table2 <-spread (Table1, road level, average daily coverage mileage)
|
In addition, tidyr providesSeparateSplits a column into multiple columns by delimiters,UniteMerges multiple columns into one column based on the specified delimiter.
R ---- introduction to the tidyr package