gpt4 book ai didi

r - 为什么在 R 中的 data.table 中使用 "could not find function "函数时会收到此错误消息 "melt"模式

转载 作者:行者123 更新时间:2023-12-05 04:11:44 27 4
gpt4 key购买 nike

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

Error in melt_check(data, id.vars, measure.vars, variable.name, value.name) : could not find function "patterns"

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

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,您需要将数据集转换为 data.table 类,方法是使用 as.data.table()setDT()

setDT(data)

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

关于r - 为什么在 R 中的 data.table 中使用 "could not find function "函数时会收到此错误消息 "melt"模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42141989/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com