I would like to change all of the column names (V1, V2, V3, ...) in a list of dataframes to the names in a vector of the same length. There are a few very similar questions, but none of them worked for my particular list. Any help is appreciated. The dataframe below (first8) doesn't recognize V1, V2, V3, ....as column names..
My vector (colnames) contains 249 names. There are also 249 variables in the list of dataframes.
I've tried several methods below that have failed yet they worked on similar examples in SO.
> for(i in 1:length(first8)){
+ colnames(first8[[i]]) <- colnames
+ }
Error in `colnames<-`(`*tmp*`, value = c("FILEID", "FILETYPE", "STUSAB", :
'names' attribute [249] must be the same length as the vector [8]
> test <- lapply(first8, setNames, colnames)
Error in FUN(X[[i]], ...) :
'names' attribute [249] must be the same length as the vector [8]
>Map(function(df, vec) setNames(df, n), first8, colnames)
Show Traceback
Rerun with Debug
Error in setNames(df, n) :
'names' attribute [249] must be the same length as the vector [8]
What am I doing wrong? Thank you.