Skip to content
Prev 369584 / 398503 Next

comparing columns and printing overlapping rows

There are missing details, such as:

  what do you mean by "overlapping"?
  do the "files" have the same number of rows?
  do you care whether the "overlapping" entries are in the same row?
  what kind of R data structure do you have the "files" stored in?

Assuming your file 1 is stored in a vector and your file 2 is stored in a data frame,
then this example shows one possibility.

## make some example data
f1 <- c('a','b')

f2 <- data.frame( c1=sample(letters[1:5] , 6, replace=TRUE),
                 c2=1:6,
                 c3=month.abb[1:6]
                 )

## find rows in f2 in which a value in the first column of f2 is found in f1
subset(f2, f2$c1 %in% f1)


oh, and,
where's your reproducible example? which is generally expected; please see the posting guide
please don't send html email to r-help, it usually makes email unreadable on r-help