I have such a list(list1) each element is a data frame which consist one column.
All columsn names are same "x". I want to change column names as "x1", "x2",....,"xn".
I use below code:
lapply(list1, function(x) setNames(x, "x",paste("x",1:seq_along(list1))))
However, this code does not work. Why does not this code work? I will be very glad for any help. Thanks a lot.
@ David Arenburg, I edited code as below(10 is the elment number in list1):
lapply(list1, function(z) setNames(z,paste0("x",1:10)))
This code does not give any error but it also does not change the column names.The column names ars still "x".
I edited the as below, however, it doesn't still work.
for(i in 1:10)
{
list2[[i]]<-setNames(data.frame(list1[[i]])[,1], paste0("x",1:10)[i])
}
I removed seq_along
for now. I will work on it after gettin the desired result.
Each element of list1 is a data frame and each data frame has only one column.