x <- c( "oranges", "bananas", "apples", "apples","pear")
y <- c("apples", "bananas","oranges","blueberry")
which(x %in% y)
which(y %in% x)
match(x,y)
match(y,x)
index=na.omit(match(x,y))
y[index]
x <- c( "oranges", "bananas", "apples", "apples","pear")
y <- c("apples", "bananas","oranges","blueberry")
which(x %in% y)
[1] 1 2 3 4
which(y %in% x)
[1] 1 2 3
match(x,y)
[1] 3 2 1 1 NA
match(y,x)
[1] 3 2 1 NA
index=na.omit(match(x,y))
y[index]
[1] "oranges" "bananas" "apples" "apples"
loc <- which(x %in% y)
loc
x[loc]
index=na.omit(match(x,y))
index
y[index]
loc <- which(x %in% y)
loc
[1] 1 2 3 4
x[loc]
[1] "oranges" "bananas" "apples" "apples"
index=na.omit(match(x,y))
index
[1] 3 2 1 1
attr(,"na.action")
[1] 5
attr(,"class")
[1] "omit"
y[index]
[1] "oranges" "bananas" "apples" "apples"