关于 r:为什么 dcast 在 reshape2 中不起作用? | 珊瑚贝

Why is dcast not working in reshape2?


为 reshape package (Wickham 2007) 发表的这篇论文给出了这个例子:

1
2
3
4
library(reshape2)
ffm <- melt(french_fries, id = 1:4, na.rm = TRUE)

dcast(ffm, variable ~ ., c(min, max))

同样,这在 reshape2 中不起作用,但似乎在 Wickham 2007 中起作用

1
dcast(ffm, variable ~ ., summary)

但是 cast 函数给出了一个错误。如何让功能正常工作?

  • 本文使用 reshape 而不是 reshape2,更重要的是,它使用 cast 函数而不是 dcast 函数。


本文针对的是 reshape 包,而不是 reshape2 包。您也没有按照编写的方式复制示例。应该是:

1
2
3
library(“reshape”) # not explicit in the paper, but implied since it is for the reshape pacakge
ffm <- melt(french_fries, id = 1:4, na.rm = TRUE)
cast(ffm, treatment ~ rep, c(min, max))

注意函数调用是cast,而不是dcast。这一变化是两个软件包之间的主要变化之一。另一个是在重塑的同时删除多个聚合,因为这被认为可以由 plyr 包更好地处理。如果您使用 reshape 包(仍可从 CRAN 获得),则示例可以工作。

  • 你知道为什么 reshape2 中删除了使用 min()、max() 和 summary() 等函数的功能吗?
  • @luciano 您仍然可以使用这些功能,但一次只能使用一个。如果你正在做多重聚合,你可能最好使用 plyr。


来源:https://www.codenong.com/18497959/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9900.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?