Select df data according to data from a list

4

Expensive as shown below:

nr <- c(100:199)
dt <- rep("data",100)
x <- data.frame(nr,dt)
y <- c(110:115)

I need to get, with the common numbers between the first column of the data.frame x and the list and

match <- x[x[1] == (lapply(x[1], function(z) which(y %in% z))),]
print(match)

But I have the error:

"Warning message:
  In FUN(left, right) :
  longer object length is not a multiple of shorter object length"

The expected result should look like this:

110 "data"
111 "data"
112 "data"
113 "data"
114 "data"
115 "data"
    
asked by anonymous 24.05.2017 / 20:38

1 answer

4

follows code that returns the result you expect

match <- x[which(x$nr %in% y), ]
    
24.05.2017 / 22:40