Cited from the Book "Beginning Data Science in R"
gather() transforms the data frame so that you get one column containing the name of your original columns and another column containing the values in those columns.
iris %>%
gather(key = Attribute, value = Measurement,
Sepal.Length, Sepal.Width)
This code tells gather() to make a column called Attributes that contains the names of columns from the input data frame and another called Measurement that will contain the values of the key columns. From the resulting data frame, you can see that the Attribute column contains the Sepal.Length and Sepal.Width names.
No comments:
Post a Comment