我有这个数据框架,其中列出了引用排名的每一个品种由三个人:
variety <- c("variety1","variety2","variety3","variety4","variety5")
people1 <- c(1, NA, 3, 2, NA)
people2 <- c(4, 3, 2, 1, NA)
people3 <- c(3, 2, 5, 4, 1)
df <- data.frame(variety, people1, people2, people3); df
我想要一个列表或 Dataframe ,如下所示:
people1 <- c("variety1", "variety3", "variety4",NA,NA)
people2 <- c("variety4", "variety3", "variety2", "variety1", NA)
people3 <- c("variety5", "variety2", "variety1", "variety4", "variety3")
df2 <- data.frame(people1, people2, people3); df2
所以每一列都代表一个人(people),并且按照输入df中给出的顺序(rank)列出了品种名称。
谢谢你,
1条答案
按热度按时间umuewwlo1#
函数
pivot_wider
和pivot_longer
对于重构数据非常有用。