我正在尝试通过行名称获取R中的数据子集,但是我遇到了流动错误。
mydata
是我的主要数据文件,我想通过行名获取它的子集。
我尝试的是:
data<-mydata[c("hsa-miR-150" , "hsa-miR-16" , "hsa-miR-192" , ..`enter code here`.. )]
我得到了:error: unexpected string constant in "sa-miR-16" , "hsa-miR-192" ,....
我也尝试过这个:
attributes(Arow)
$levels
[1] "hsa-miR-150" "hsa-miR-16" "hsa-miR-192" "hsa-miR-194" "hsa-miR-19a"
[6] "hsa-miR-19b" "hsa-miR-22"
> p<-matrix(nrow=16, ncol=1)
> p<-matrix(nrow=16, ncol=1, Arow)
> y<-mydata[p]
> dim(y)
>NULL
此外,即使这个简单的代码也不适合我!:
y<-c("hsa-miR-150" , "hsa-miR-16" , "hsa-miR-192" , "hsa-miR-194" , "hsa-miR-19a", "hsa-miR-19b" , "hsa-miR-22" , "hsa-miR-223" , "hsa-miR-23a" ,"hsa-miR-23b" ,"hsa-miR-25" , "hsa-miR-30b" ,"hsa-miR-30c" , "hsa-miR-425" , "hsa-miR-486-5p" "hsa-miR-92a" )
Error: unexpected string constant in "sa-miR-16" , "hsa-miR-192" , "hsa-miR-194" , "hsa-miR-19a",
有人可以告诉我,这里出了什么问题?!我该怎么办?
答案 0 :(得分:1)
首先阅读:How to make a great R reproducible example?。
然后删除enter code here
并在行列表后添加逗号:
data <- mydata[c("hsa-miR-150", "hsa-miR-16", "hsa-miR-192"), ]
然后你可以在这里添加缺少的逗号:
y <- c("hsa-miR-150", "hsa-miR-16", "hsa-miR-192", "hsa-miR-194",
"hsa-miR-19a", "hsa-miR-19b", "hsa-miR-22", "hsa-miR-223",
"hsa-miR-23a", "hsa-miR-23b", "hsa-miR-25", "hsa-miR-30b",
"hsa-miR-30c", "hsa-miR-425", "hsa-miR-486-5p", "hsa-miR-92a" )
答案 1 :(得分:1)
此错误通常与缺少语法有关,例如逗号或=
。你的最后一个例子是缺少一个逗号,最后两个项目没有用逗号分隔。这有效:
y<-c("hsa-miR-150" , "hsa-miR-16" , "hsa-miR-192" , "hsa-miR-194" , "hsa-miR-19a", "hsa-miR-19b" , "hsa-miR-22" , "hsa-miR-223" , "hsa-miR-23a" ,"hsa-miR-23b" ,"hsa-miR-25" , "hsa-miR-30b" ,"hsa-miR-30c" , "hsa-miR-425" , "hsa-miR-486-5p", "hsa-miR-92a" )
与任何编程语言一样,R是一种形式语言,使用正确的语法非常重要。因此,在编写代码时,请仔细检查是否使用了正确的语法。