问题描述
这很可耻,但我仍然无法完全理解 tidyr
,特别是 gather()
.我觉得我缺少一些基本的东西.
It's shameful, but I still can't wrap my mind fully around tidyr
, specifically gather()
. I feel like I'm missing something fundamental.
如果我运行这段代码
library(tidyr)
x <- data.frame(var1=letters[1:3], var2=LETTERS[7:9], var3=21:23)
gather(x, foo, value)
我明白
> x
var1 var2 var3
1 a G 21
2 b H 22
3 c I 23
> gather(x, foo, value)
variable value
1 var1 a
2 var1 b
3 var1 c
4 var2 G
5 var2 H
6 var2 I
7 var3 21
8 var3 22
9 var3 23
foo
在哪里使用?这完全没有必要吗?我是不是绊倒了,因为我在想 reshape
风格,你定义 ID
变量,其余的得到 melt
ed 而我应该有不同的想法你在哪里定义变量gather
,其余的被认为是ID
?
Where does foo
get used? Is this completely unnecessary? Am I tripping up because I'm thinking reshape
style where you define the ID
variables and the rest get melt
ed whereas I should be thinking differently where you define the variables to gather
and the rest are considered ID
?
推荐答案
这是在加载 reshape
和 tidyr
时发生的错误.tidyr 0.3.1
中已修复.
This is a bug that occurs when reshape
and tidyr
are both loaded. It has been fixed in tidyr 0.3.1
.
这篇关于为什么gather() 不使用关键变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!