为什么gather() 不使用关键变量名? [英] Why doesn't gather() use the key variable name?

查看:26
本文介绍了为什么gather() 不使用关键变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很可耻,但我仍然无法完全理解 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 变量,其余的得到 melted 而我应该有不同的想法你在哪里定义变量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 melted whereas I should be thinking differently where you define the variables to gather and the rest are considered ID?

推荐答案

这是在加载 reshapetidyr 时发生的错误.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() 不使用关键变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆