-3

I have a scenario where I want to compare 3 different .csv files and extract/write the data which is common in them to a 4th file.Can anyone advise me how to achieve this in R.

AChampion
  • 29,683
  • 4
  • 59
  • 75
total_noob
  • 23
  • 3
  • 2
    try `?merge` `?read.csv` `?write.csv` and check this : https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right – moodymudskipper Jun 16 '17 at 17:50

1 Answers1

0

You could use dplyr to perform all operations in one pipe.

If you are looking for a solution finding observations that are present in ALL .csv files you should go with inner join:

library(dplyr)
library(magrittr)

read.csv("first.csv") %>%
  inner_join(read.csv("second.csv")) %>%
  inner_join(read.csv("third.csv")) %>%
  write.csv("fourth.csv", quote = F, row.names = F)

If you are looking for a solution that find all observations present in ANY data frame you should go with full join:

read.csv("first.csv") %>%
  full_join(read.csv("second.csv")) %>%
  full_join(read.csv("third.csv")) %>%
  write.csv("fourth.csv", quote = F, row.names = F)
Niko
  • 341
  • 1
  • 8