1

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)
})
aynber
  • 22,380
  • 8
  • 50
  • 63
Mar
  • 117
  • 10

1 Answers1

1

The issue is because the columns were factor. So, we unlist and convert to character class

names(x) <- as.character(unlist(x[1,]))
akrun
  • 874,273
  • 37
  • 540
  • 662