merge - Change column names after merging multiple data frames into one in R -


after merging multiple data frames one, know how change column headers in master data frame represent original files came from. merged large number of data frames 1 using code below:

library(plyr)   dflist = list.files(path=dir, pattern="csv$", full.names=true, recursive=false)  import.list = llply(dflist, read.csv)  master = reduce(function(x, y) merge(x, y, by="hours"), import.list) 

i columns belonged each original data frame named unique id original data frame/ csv file named (i.e. aa, ab, ac). unique ids in filenames comes before low line ("_") can isolate them using code below. however, having trouble applying column headers. appreciated.

filename = dflist[1] unqid = strsplit(filename,"_")[[1]][1] 

you define function in llply call , have read.csv assign names. or rename them after reading them in , before merging @joran suggested

#first names filenames = dflist #i unsure line below, unqid = lapply(filenames,function(x) strplit(x,"_")[1]) names(import.list) <- paste("unqid", names(import.list),sep=".") #renaming list items 

and merge using code


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -