简体   繁体   English

在R中如何从数据框中选择行?

[英]In R how to select rows from a dataframe?

I have a column "Year" in my dataframe ("import") and I need to only select 2015 out of some 30 years. 我在数据框(“导入”)中有一列“年份”,我只需要从30年中选择2015年即可。 However none of the steps I tried worked. 但是,我尝试的所有步骤均无效。 Things I tried include: 我尝试过的事情包括:

iy2015<-subset(import, import$year==2015)
iy2015<-import[which(import$year==2015),]
iy2015<-import[import$year==2015,]

all have given me an empty dataframe. 所有人都给了我一个空的数据框。

For me your last option works, check if 2015 is in the column and check whether year is a column name. 对我来说,您的最后一个选择有效,请检查列中是否包含2015,并检查年份是否为列名。 I used: iy2015 = import[import$Year==2015,] 我曾经使用过: iy2015 = import[import$Year==2015,]

EDIT: 编辑:

You need to use Year instead of year. 您需要使用Year而不是Year。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM