繁体   English   中英

基本重整功能中的像reshape2包这样的任务会执行什么代码?

[英]What code does a task like the reshape2 package in a base reshape function?

我正在学习重塑功能(基于R),其功能类似于hadley wickham的reshape2包。 我使用reshape2包编写了以下代码。

melt(iris, id.vars = 'Species')

结果:列名称为Species,变量,值,结果的总数为600

我写了这段代码

reshape(iris, idvar = 'Species', direction = 'long')

但是显示错误信息

重塑错误(iris,idvar =“ Species”,方向=“ long”):“无'reshapeWide'属性,必须指定'varying'

如何在reshape2包中看到执行melt功能的相同结果?

至少指定varying ,最好指定所有所示的那些:

nm <- names(iris)[-5]
long <- reshape(iris, dir = "long",
  varying = list(nm), times = nm, timevar = "Attribute", v.names = "value")

long的前几行是:

> head(long)
               Species    Attribute value id
1.Sepal.Length  setosa Sepal.Length   5.1  1
2.Sepal.Length  setosa Sepal.Length   4.9  2
3.Sepal.Length  setosa Sepal.Length   4.7  3
4.Sepal.Length  setosa Sepal.Length   4.6  4
5.Sepal.Length  setosa Sepal.Length   5.0  5
6.Sepal.Length  setosa Sepal.Length   5.4  6

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM