简体   繁体   English

dcast错误:`匹配错误(x,表,nomatch = 0L)`

[英]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.

相关问题 匹配错误(x,表,nomatch = 0L):“匹配”需要向量参数 - Error in match(x, table, nomatch = 0L) : 'match' requires vector arguments 修拉中的 FindVariableFeatures Function 产生“匹配错误(x,表,nomatch = 0L):'匹配'需要向量参数” - FindVariableFeatures Function in Seurat Producing “Error in match(x, table, nomatch = 0L) : 'match' requires vector arguments” 使用ggsurplot时匹配错误(x,表,不匹配= 0L - Error in match(x, table, non match =0L when using ggsurplot 匹配错误(el,set,0L):“匹配”需要向量参数? - Error in match(el, set, 0L) : 'match' requires vector arguments? Foverlaps 错误: if (any(x[[xintervals[2L]]] - x[[xintervals[1L]]] &lt; 0L)) 中的错误停止 - Foverlaps error: Error in if (any(x[[xintervals[2L]]] - x[[xintervals[1L]]] < 0L)) stop 非等值内部联接(nomatch = 0L)是否应该是双向的? - Should non-equi inner join (nomatch=0L) be bidirectional? if(REML)p else 0L时出错:参数长度为零 - Error in if (REML) p else 0L : argument is of length zero 尝试绘制createTreeView并获取工具中的错误::: httpdPort&gt; 0L - Trying to plot createTreeView and get the Error in tools:::httpdPort > 0L Rstudio中的“工具中的错误::: httpdPort <= 0L:...”是什么意思? - What does “Error in tools:::httpdPort <= 0L : …” in Rstudio means? 错误:使用 data.table 索引时未使用的参数(nomatch = 0) - error: unused argument (nomatch = 0) when using data.table indexing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM