根据R中的行号向量从数据帧中提取值 [英] extract values from a data frame based on a vector of row numbers in R
本文介绍了根据R中的行号向量从数据帧中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试根据行号矢量从数据帧中提取值矢量;
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)
我想要向量x中列出的行号的相应Species.我尝试了类似 df $ Species [x,]
和 df $ Species [list(x),]
之类的方法,但无济于事.我相信答案确实很简单,但我看不到!
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!
预先感谢
推荐答案
尝试
df[x,]$Species
或
df[,"Species"][x]
或者实际上
df[x,"Species"]
这篇关于根据R中的行号向量从数据帧中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文