tips and tricks: subset data frame rows by a vector

6 views
Skip to first unread message

Lauren Hodgson

unread,
Aug 15, 2012, 1:42:03 AM8/15/12
to tropi...@googlegroups.com
Cool trick i just learned!

Subset data frame rows by a vector:

rows.you.want=c('a','b')
origData=data.frame(cbind(x=letters[1:10],y=1:10))

subsetOfData = origData[origData$x %in% rows.you.want,] #remember to put that comma to specify that you want all columns of the original data in your subset
Reply all
Reply to author
Forward
0 new messages