0

我正在尝试通过行名获取 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", 

谁能告诉我,这里出了什么问题?!我该怎么办?

4

2 回答 2

1

从阅读以下内容开始:如何制作一个出色的 R 可重现示例?.

然后在行列表后删除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" )
于 2013-09-23T08:40:55.753 回答
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 与任何编程语言一样,是一种形式语言,使用正确的语法非常重要。因此,当您编写代码时,请仔细检查您是否使用了正确的语法。

于 2013-09-23T08:41:19.473 回答