gpt4 book ai didi

r - dcast 错误 : `Error in match(x, table, nomatch = 0L)`

转载 作者:行者123 更新时间:2023-12-04 19:17:24 28 4
gpt4 key购买 nike

我有一个名为 df 的数据框看起来像这样......

"ID","ReleaseYear","CriticPlayerPrefer","n","CountCriticScores","CountUserScores"
"1",1994,"Both",1,5,283
"2",1994,"Critics",0,0,0
"3",1994,"Players",0,0,0
"4",1995,"Both",3,17,506
"5",1995,"Critics",0,0,0
"6",1995,"Players",0,0,0
"7",1996,"Both",18,163,3536
"8",1996,"Critics",2,18,97
"9",1996,"Players",3,20,79

我想翻转数据框,所以列是这样的:
"ReleaseYear","Both","Critics","Players"
列的值 Both',评论家 and玩家 would be the n` 每个。

当我尝试运行这个...
require(dcast)
chartData.CriticPlayerPreferByYear <- dcast(
data = df,
formula = ReleaseYear ~ CriticPlayerPrefer,
fill = 0,
value.var = n
)

...我收到此错误:
Error in match(x, table, nomatch = 0L) : 
'match' requires vector arguments

这里有什么问题?我如何解决它?

最佳答案

你好像少了引号?

data <- read.table(text='"ID","ReleaseYear","CriticPlayerPrefer","n","CountCriticScores","CountUserScores"
"1",1994,"Both",1,5,283
"2",1994,"Critics",0,0,0
"3",1994,"Players",0,0,0
"4",1995,"Both",3,17,506
"5",1995,"Critics",0,0,0
"6",1995,"Players",0,0,0
"7",1996,"Both",18,163,3536
"8",1996,"Critics",2,18,97
"9",1996,"Players",3,20,79"',header=T,sep=",")

library(reshape2)
dcast(data, ReleaseYear ~ CriticPlayerPrefer, value.var="n")

# ReleaseYear Both Critics Players
# 1994 1 0 0
# 1995 3 0 0
# 1996 18 2 3

这就是我得到的。是想要的结果吗?

关于r - dcast 错误 : `Error in match(x, table, nomatch = 0L)` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39339334/

28 4 0