0
我通常會將一堆.csv文件讀入數據框列表中並手動命名。來自數據幀的數據幀名稱列表
#...code for creating the list named "datos" with files from library
# Naming the columns of the data frames
names(datos$v1r1)<-c("estado","tiempo","x1","x2","y1","y2")
names(datos$v1r2)<-c(...)
names(datos$v1r3)<-c(...)
我想自動執行此重命名操作。爲此,我在我的datos
列表中爲每個數據框創建了一個我想要的名稱的數據框。
這是我如何生成該數據幀:
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)
由於nombres_df$corrida[1]
是v1r1
,我必須以命名datos$v1r1
("estado","tiempo", nombres_df[1,2:5])
列,依此類推對於其它40個元素。 我想自動重命名。我在想我可以使用使用正則表達式的東西。
只是爲了記錄,我不知道爲什麼,但數據幀列表的順序是不一樣的1:20序列(由此我的意思是10之前2,3,4 ... ... )
下面是一個具有相似結構但數量較少和較短的列表的玩具示例。
toy<-list(a=replicate(6,1:5),b=replicate(6,10:14))