I have many csv files in one directory. All the files have the same columns structure such as:
Class val1 val2
A 6.5 2.3
F 9 6.8
I would like to find the name of the classes that exist in all the CSV files. In other words, I would like to get the intersection of all the files based on the Class
column and regardless to the values in val1
and val2
.
I applied the following:
temp = list.files(pattern="*.csv")
myfiles = lapply(temp, read.delim)
x <- Reduce(intersect,myfiles)
But this will retrieve similar classes along with similar values, which I don't want. I only want the name of classes that are in all files.