r - How to add/merge dataframes in a list -


i used following loop read 7 csv files , add them list.

list <- list() l <- 1 for(i in 1:7){       data <- read.csv(paste("file",i,".csv",sep=""),header=false)        list[[l]] <- data        l <- l + 1 } 

so have list named "list" containing 7 dataframes, right?

each of 8 dataframes contain same 3 columns (name, surname, age). want add:

df <- dataframe(name,surname,age) ## each dataframe in list. 

did @ all? question is, how can achieve 7 objects in list automatically!

if 'lst' has 7 data.frames , want 'rbind' 8th dataset each of datasets in list, can use map

 map(rbind, lst, list(d1)) 

or using lapply

lapply(lst, rbind, d1) 

update

if 'lst' of length 8, , wants rbind first 7 elements dataset in 8th element, can do

 map(rbind, lst[-8], lst[8]) 

data

set.seed(24) lst <- lapply(1:7, function(i) as.data.frame(matrix(sample(0:10, 3*10,           replace=true), ncol=3)))  set.seed(49) d1 <- as.data.frame(matrix(sample(1:20, 3*10, replace=true), ncol=3)) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -