简体   繁体   中英

Change dataframes names in loop in R

I have a set of data frames with names RI** where ** denotes different numbers. All of them contains same data for different periods. I want change columns names of all these data frames. I wrote:

varNames <- c('varName1','varName2',...)
dfList <- c('RI11','RI12',...)
for (i in dfList) {colnames(i) <- varNames}

But this doesn't help. I got message "Error in names(i) <- varNames : 'names' attribute [15] must be the same length as the vector [1]"

I tried to use apply function but did not get it.

我将使用setNames

 dfList <- lapply(dfList,setNames,varNames)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM