I am trying to extract a vector of values from a data frame based on a vector of row numbers;
我试图根据行号向量从数据帧中提取值向量;
df<-iris
x<-c(1,5,15,8,7,2)
I want the corresponding Species of the row numbers listed in the vector x. I have tried something like df$Species[x,]
and df$Species[list(x),]
to no avail. I am sure the answer is something really simple but I just can't see it!
我想要向量x中列出的行号的相应种类。我尝试过像df $ Species [x,]和df $ Species [list(x),]这样的东西无济于事。我确信答案很简单,但我看不到它!
Thanks in advance
提前致谢
1 个解决方案
#1
2
Try
尝试
df[x,]$Species
or
要么
df[,"Species"][x]
or indeed
或者确实
df[x,"Species"]
#1
2
Try
尝试
df[x,]$Species
or
要么
df[,"Species"][x]
or indeed
或者确实
df[x,"Species"]