繁体   English   中英

为什么在 R 中的 data.table 中使用“熔化”函数时会收到此错误消息“找不到函数”模式

[英]Why do I get this error message "could not find function "patterns" when using the "melt" function in data.table in R

我正在使用 data.table(版本 1.10.4)清理数据(顺便说一句,我已经安装了“reshape2”),但我收到了这条消息:

melt_check(data, id.vars, measure.vars, variable.name, value.name) 出错:找不到函数“模式”

我检查了很多次,但不明白为什么。 我在下面发布我的代码,任何人都可以看看它,并告诉我我哪里错了吗? 谢谢。

library(reshape2)
library(data.table)
library(readxl)
data<-read_excel("Time3Ratee.xlsx")
meltdata<-melt(data,id = 1:4, measure = patterns ("^ratee\\d+$","^RICB.peer\\d+\\.1", "^RICB.peer\\d+\\.2","^RICB.peer\\d+\\.3", "^TICB.peer\\d+\\.1", "^TICB.peer\\d+\\.2","^TICB.peer\\d+\\.3","^LE.peer\\d+\\.1", "^LE.peer\\d+\\.2","^LE.peer\\d+\\.3","^LE.peer\\d+\\.4", "^DEV.peer\\d+\\.1", "^DEV.peer\\d+\\.2","^DEV.peer\\d+\\.3"), value.name = c("ratee", "RICB.peer.1", "RICB.peer.2","RICB.peer.3", "TICB.peer.1", "TICB.peer.2","TICB.peer.3", "LE.peer.1", "LE.peer.2","LE.peer.3","LE.peer.4", "DEV.peer.1", "DEV.peer.2","DEV.peer.3"))

(将@Franks 评论转换为答案)

为了能够使用data.table::melt ,您需要使用as.data.table()setDT()将数据集转换为data.table

setDT(data)

否则, melt将默认为reshape2::melt并且您将无法使用 data.tables 功能,例如patterns

暂无
暂无

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

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