[R] truncating a data frame based on a function

Faheem Mitha faheem at email.unc.edu
Fri Sep 21 17:24:12 CEST 2007


Consider the following example.

> a = c(1,2,3); b = c(4,5,6); c = cbind(a,b); c[(2 < c[,1]) & (c[,1] < 4),]

a b
3 6

So, the idea is to select rows for which the value in the first column is 
between 2 and 4. This works, however, I don't like having to reference a 
explicitly in this fashion, and just wondered if there was a preferred way 
to accomplish the same thing. Ideally, I'd like to make use of a function.

                                                            Thanks, Faheem.

More information about the R-help mailing list