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
Post a Comment