简体   繁体   中英

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. 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. I used: iy2015 = import[import$Year==2015,]

EDIT:

You need to use Year instead of year.

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.

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