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
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
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
3 matches
Mail list logo