【发布时间】:2019-08-24 13:37:47
【问题描述】:
我正在学习 reshape 函数(base R),它的工作原理类似于 hadley wickham 的 reshape2 包。
我使用reshape2 包编写了下面的代码。
melt(iris, id.vars = 'Species')
结果: 列名是 Species 、变量、值,结果的整数是 600
我写了这段代码
reshape(iris, idvar = 'Species', direction = 'long')
但是显示错误信息
重塑错误(iris, idvar = "Species", direction = "long") : "no “reshapeWide”属性,必须指定“可变”
如何查看在reshape2 包中执行melt 函数的相同结果?
【问题讨论】:
-
嗨,Jh J,仅供参考,这些软件包不在基础中;
reshape和reshape2包均由 Hadley 提供。并且这两个包都被tidyr库所取代,其中包含gather()和spread()。见tidyr.tidyverse.org -
reshape函数在基础 R 中。find("reshape") -
@G.Grothendieck 你是对的,我混淆了基本函数
stats::reshape()和reshape::melt()包。