根据R中的行号向量从数据帧中提取值 [英] extract values from a data frame based on a vector of row numbers in R

查看:37
本文介绍了根据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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆