Re: [R] function in R that's equivalent to SQL's "IN"

2007-10-26 Thread Gabor Grothendieck
Here are a few ways: with(z, y[x %in% w]) subset(z, x %in% w)$y z[z$x %in% w, "y"] z$y[z$x %in% w] # see sqldf.googlecode.com for more info library(sqldf) sqldf("select y from z where x in (2, 3, 5)") # but if you know that x is 1:n and the components of w are in # that s

Re: [R] function in R that's equivalent to SQL's "IN"

2007-10-26 Thread Benilton Carvalho
z$y[z$x %in% w] b On Oct 26, 2007, at 4:19 PM, Em C wrote: > Hi all, > > I'm trying to find > something like the "==" operator that will work on vectors or > something > equivalent to SQL's "IN" function. For e.g., if I have: > > x <- c(1,2,3,4,5) > y <- c("apples", "oranges", "grapes", "banan

[R] function in R that's equivalent to SQL's "IN"

2007-10-26 Thread Em C
Hi all, I'm trying to find something like the "==" operator that will work on vectors or something equivalent to SQL's "IN" function. For e.g., if I have: x <- c(1,2,3,4,5) y <- c("apples", "oranges", "grapes", "bananas", "pears") z <- data.frame (x,y) w <- c(2,4,5) I want R to return the values