r - Name list of data frames from data frame -
i read bunch of .csv files list of data frames , name manually doing.
#...code creating list named "datos" files library # naming columns of data frames names(datos$v1r1)<-c("estado","tiempo","x1","x2","y1","y2") names(datos$v1r2)<-c(...) names(datos$v1r3)<-c(...)
i want renaming operation automatically. so, created data frame names want each of data frames in datos
list.
here how generate data frame:
pru<-rbind(c("ut","tr","ut+","tr+"), c("ut","tr","ut+","tr+"), c("tr","ut","tr+","ut+"), c("tr","ut","tr+","ut+")) vec<-paste("v1r",seq(1,20,1),sep="") tor<-paste("v1s",seq(1,20,1),sep="") nombres<-do.call("rbind", replicate(10, pru, simplify = false)) nombres_df<-data.frame(corrida=c(vec,tor),nombres)
because nombres_df$corrida[1]
v1r1
, have name datos$v1r1
columns ("estado","tiempo", nombres_df[1,2:5])
, , on other 40 elements. want renaming automatically. thinking use uses regular expressions.
just record, don't know why order of list of data frames not same 1:20 sequence (by mean 10 comes before 2,3,4...)
here's toy example of list similar structure fewer , shorter data frames.
toy<-list(a=replicate(6,1:5),b=replicate(6,10:14))
you have data frame variable corridas
name of data frame renamed , remaining columns desired variable names data frame. use loop renaming operations:
for (i in seq_len(nrow(nombres_df))) { names(datos[[nombres_df$corridas[i]]]) <- c("estado","tiempo",nombres_df[i,2:length(nombres_df)]) }
Comments
Post a Comment