-2

I currently have a set of values in one table, and I would like to find these values in another larger table and filter the rows so that only rows containing these values remain.

I've tried using filter(), but it keeps erroring by saying longer object length is not a multiple of shorter object length. Not sure if this is part of the reason it doesn't work, but filter works if I plug in each value individually rather than trying to filter for the whole set of values at once.

filter(table1, table1$desiredvalues==table2$generalvalues)

I was expecting an output of all the values from table1 found in table2, but it only showed a very small subset of values from table1 for some reason.

M--
  • 25,431
  • 8
  • 61
  • 93
tamcle
  • 15
  • 5

1 Answers1

0

If you know SQL, R has provided a wonderful feature to execute SQL query.

library(sqldf)

 ## syntax: sqldf("sql query")

sqldf("select * from table1 inner join table2 on table1.a = table2.a")
M--
  • 25,431
  • 8
  • 61
  • 93
  • If the column names are the same then this also works: `sqldf("select * from table1 inner join table2 using(a)")` . Also note that if each line of code in a post is indented by 4 spaces then SO will format it nicely. – G. Grothendieck Jun 15 '19 at 14:43