Question

I have a created a list of data frames using the code below. I would like to conduct following operations on this list:

  1. Delete second row from each of the data frames
  2. Merge the data frames by common identifier available in the first column

    files = list.files(pattern="*.csv")
    library(plyr)
    list_dataframes <- llply(files, read.table, header = T, sep = ",")
    imax <- length(list_dataframes)
    i <- 1
    for (i in imax) {
            list_dataframes[[i]] = list_dataframes[[i]]
            i <- i + 1
        }
    
Was it helpful?

Solution

Delete second row from each of the data frames

list_dataframes <- lapply(list_dataframes, function(x) x[-2,])

Merge the data frames by common identifier available in the first column

DF <- Reduce(function(x ,y) merge(x, y, by=names(x)[1]), list_dataframes)

(Not tested due to lack of reproducible example.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top