[R] selecting certain rows from a data.frame

Sean Davis sdavis2 at mail.nih.gov
Fri Mar 5 13:21:30 CET 2004


On 3/5/04 6:17 AM, "Monica Palaseanu-Lovejoy"
<monica.palaseanu-lovejoy at stud.man.ac.uk> wrote:

> Meanwhile i have this new question: suppose i have a data.frame
> with x and y columns and 10 rows, 1 to 10. I also have a variable m
> (or an array if you like) with 5 numbers that represent some of the
> row order numbers in my data.frame. Let's make m(1, 4, 5, 8, 10).
> How can i select from my data.frame the rows number 1, 4, 5, 8,
> and 10?

If df is the name of your dataframe:

df[c(1,4,5,8,10),]

Will select only those rows.

I would highly recommend looking at the R manual, An Introduction to R.  It
can be obtained from the CRAN homepage (http://cran.us.r-project.org/).
There is a link on the left side called Manual.

Sean




More information about the R-help mailing list