r - list - rename specific data.frames column with lapply -


i have got list 10 data.frames , need rename 1 column of each data.frame. column rename no. 7 , think can trick lapply.

here tried without success:

lst <- lapply(lst, function(x) colnames(x)[7] <- 'new_name')  

i think close solution missing something. thanks

you need use {} , return x:

lst <- lapply(lst, function(x) {colnames(x)[7] <- 'new_name'; x})  

or

lst <- lapply(lst, function(x) {   colnames(x)[7] <- 'new_name'   x       }) 

as reproducible example, use

lapply(list(iris, iris), function(x) {colnames(x)[3] <- "test"; x}) 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -