dcast error: `Error in match(x, table, nomatch = 0L)`
dcast error: `Error in match(x, table, nomatch = 0L)`
我有一个名为 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
这就是我得到的。是想要的结果吗?
我有一个名为 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
这就是我得到的。是想要的结果吗?