I'm trying to get subset of my data in R. I tried this, but I got unexpected result!
>str(data)
num [1:500, 1:2000] 5.65
>y<-c("rowname1" , "rowname2", ... )
> spotA<-data[y]
NULL
> spotA
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
also I tried as following way :
>spotA<-data[c("rowname1" , "rowname2", ... )]
and I got the above result. what I would expect is to get sotA with dimension 16 2000 with numeric entries, not NA ! can somebody help me where is my mistake ?
Try this:
data<-as.data.frame(matrix(runif(20),nrow=10,ncol=2));
y<-paste("row",row.names(data),sep=".")
row.names(data)<-y
data;
V1 V2
row.1 0.3108385 0.09000282
row.2 0.3254967 0.44500053
row.3 0.3993356 0.71400316
row.4 0.2039391 0.11712378
row.5 0.4105687 0.70830021
row.6 0.5245575 0.36039628
row.7 0.2277783 0.71712201
row.8 0.6282813 0.33950400
row.9 0.1005018 0.94331287
row.10 0.3843297 0.58610738
data[row.names(data)%in%y[c(2,4,5,8,9)],]
V1 V2
row.2 0.3254967 0.4450005
row.4 0.2039391 0.1171238
row.5 0.4105687 0.7083002
row.8 0.6282813 0.3395040
row.9 0.1005018 0.9433129
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.