I want to rename the columns of every data frame in my list of data frames with the first row.
I tried the code from this question First row as column names in a list of data frames but it returns first_row_name=rows_number / c(date=3) /
dflist1 <- lapply(dflist, function(x){
names(x) <- x[1,]
x <- x[-1,]
return(x)
})
The issue is because the columns were factor
. So, we unlist
and convert to character
class
names(x) <- as.character(unlist(x[1,]))
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.