I am using the following code to access data frames df1,df2 and df3 in a loop and rename them. This gives me an error. How do I tell R that its a data frame not a
for(i in c(df1,df2,df3)) {
colnames(data.frame(i))=c("var1","var2","var3")
}
Try using a list instead
dfl=list(df1,df2,df3)
for(i in 1:length(dfl)) {
colnames(dfl[[i]])<-c("var1","var2","var3")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.