Tidyverse users: gather/spread are on the way out
source link: https://www.tuicool.com/articles/hit/YNzeuyZ
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
From https://tidyr.tidyverse.org/dev/articles/pivot.html :
There are two important new features inspired by other R packages that have been advancing of reshaping in R:
-
The reshaping operation can be specified with a data frame that describes precisely how metadata stored in column names becomes data variables (and vice versa). This is inspired by the
cdata
package by John Mount and Nina Zumel. For simple uses ofpivot_long()
andpivot_wide()
, this specification is implicit, but for more complex cases it is useful to make it explicit, and operate on the specification data frame usingdplyr
andtidyr
. -
pivot_long() can work with multiple value variables that may have different types. This is inspired by the enhanced
melt()
anddcast()
functions provided by thedata.table
package by Matt Dowle and Arun Srinivasan.
If you want to work in the above way we suggest giving our
cdata
package a try. We named the functions
pivot_to_rowrecs
and
unpivot_to_blocks
. The idea was: by emphasizing the record structure one might eventually internalize what the transforms are doing. On the way to that we have a lot of documentation and tutorials.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK