Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How subselect all rows who's index number "greater than" some value in R?

Say I have a dataframe as follows:

A<-c(1,2,3,4)
B<-c(5,6,7,8)
C<-c(9,10,11,12)
data<-data.frame(A,B,C)

I know that I can subselect just rows 2 and 3 by the following:

data[2:3,]

My question is: how can I achieve the same by effectively saying "all rows with an index number greater than 1"? (I.e., the row indices for "data" are 1, 2, and 3. So, by requesting row indices ">1", I should get rows 2 and 3 only.)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use nrow to get the total rows and then use greater than operator.

data[1:nrow(data) > 1, ]

Also, for example if you need all indices greater than 2:

data[-c(1:2), ]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading