R ---- introduction to the tidyr package

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.