# How do I call nonconsecutive rows in an R dataframe? [closed]

Still learning basic syntax in R. Basic example code is provided below.

I know how to call consecutive rows but what if, for example, I wanted the 1st and 3rd row? Or better yet, since that is easily called by w[-2,] in this example, what if the data set was larger and I had the need to investigate the 3rd, 5th and 8th row?

> w<-data.frame(names=c("betty","freddy","sammy"),high.fiving.ability=c(50,50,100))
> w[2:3,]
names high.fiving.ability
2 freddy                  50
3  sammy                 100


BTW I looked at other posts including this one: Filtering a dataframe but what I am looking for is even more basic than that.

• You should start with some introduction to R! Here you wanna look at the c function. (solution w[c(3,5,8),]) I like Maindonald & Braun (2010): amazon.com/Data-Analysis-Graphics-Using-Example-Based/dp/… Jun 13 '12 at 22:49
• This is a perfectly good question, but because it's only about how to get R to do something, & not about any statistical issues (possibly w/ R), it belongs on Stack Overflow, not here. Jun 14 '12 at 1:19

w[c(3, 5, 8), ]