当在R中的data.table中使用“融合”功能时,为什么会出现“无法找到函数”模式的错误消息

时间:2017-02-09 16:30:47

标签: r data.table reshape reshape2

我使用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"))

1 个答案:

答案 0 :(得分:1)

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

为了能够使用data.table::melt,您需要使用data.tableas.data.table()

将数据集转换为setDT()
setDT(data)

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