Search code examples
r

Creating a list/vector from first column od multiple data


In total I have 21 csv files which I would like to load to R. So I did:

list_of_data = list.files(pattern="*.csv")
tbl_met = lapply(list_of_data, read.csv)

Can't give you the dput because it's too much data...

What I want to do is to get a list off all names in first column in all datasets. Combined to one vector/list but there are 2 problems:

  • first of all the columns in those files are separated by ";" or without any separation mark... Do I have to look inside those files and make them all separated in the same way ?

  • second problem is that there might be duplicates of names and I'd like to remove them from the list.

Do you have any idea how to do that ? Should I provide you some more data ? If yes, let me know how to do that.


Solution

  • This solves my problem:

    list_of_data = list.files(pattern="*.csv")
    tbl_met = lapply(list_of_data, read.csv)
    tbl <- data.table::rbindlist(tbl_met) ## binding all of the tables in the list by row
    
    vec_names <- tbl$locus ## name of the column with names which I am interested in
    vec <- unique(vec_names) ## removing the duplicates