[英]dcast error: `Error in match(x, table, nomatch = 0L)`
I have a dataframe called df
that looks something like this... 我有一个名为
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
I want to flip the data frame around so the columns are like this: 我想翻转数据框,所以列是这样的:
"ReleaseYear","Both","Critics","Players"
The values for columns Both',
Critics and
Players would be the
n` for each. 列
Both',
Critics and
Players的值would be the
每个列would be the
n`。
When I try running this... 当我尝试运行这个...
require(dcast)
chartData.CriticPlayerPreferByYear <- dcast(
data = df,
formula = ReleaseYear ~ CriticPlayerPrefer,
fill = 0,
value.var = n
)
... I get this error: ...我收到此错误:
Error in match(x, table, nomatch = 0L) :
'match' requires vector arguments
What is the problem here? 这里有什么问题? How do I fix it?
我如何解决它?
You seem to be missing quotation marks? 你似乎缺少引号?
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
This is what I get. 这就是我得到的。 Is it the desired result?
这是理想的结果吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.