使用 tidyr 收集:位置必须介于 0 和 n 之间,错误 [英] gather with tidyr: position must be between 0 and n error
本文介绍了使用 tidyr 收集:位置必须介于 0 和 n 之间,错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些数据如下:
x.row10 <- setNames(data.frame(letters[1:3],1:3,2:4,3:5,4:6,5:7,6:8,7:9),
c("names",2004:2009,2012))
# names 2004 2005 2006 2007 2008 2009 2012
#1 a 1 2 3 4 5 6 7
#2 b 2 3 4 5 6 7 8
#3 c 3 4 5 6 7 8 9
现在我可以使用 tidyr
包中的 gather()
使它们变长:
Now I can make them long with gather()
from the tidyr
package by writing:
x.row10 %>% gather(Year, Val, -names)
但是当我使用
x.row10 %>% gather(Year, Val, c(2004:2009,2012))
这是我的直觉选择,我收到错误消息
which is my intuitive choice, I get the error message
错误:位置必须在 0 和 n 之间
Error: Position must be between 0 and n
这是怎么回事,如何解决?
How come and how can this be resolved?
推荐答案
x.row10 %>% gather(Year, Val, c(2:8))
这篇关于使用 tidyr 收集:位置必须介于 0 和 n 之间,错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文