I have list of data.frames.
> LoDFs <- list(data.frame(y1=c(1,2,3), y2=c(4,5,6)), data.frame(yA=c(1,2,3), yB=c(4,5,6)))
> LoDFs
[[1]]
y1 y2
1 1 4
2 2 5
3 3 6
[[2]]
yA yB
1 1 4
2 2 5
3 3 6
Here I've found how to use lapply
function to manipulate each data.frame separately. My goal is to change the column names in particular data.frame (both data.frames should have first column named A
and second B
). I've tried following:
> col.names <- c("A", "B")
> lapply(seq_along(LoDFs), function(x) {colnames(LoDFs[[x]]) <- col.names})
[[1]]
[1] "A" "B"
[[2]]
[1] "A" "B"
But it just returns the modification and didn't affect the particular data.frame:
> LoDFs
[[1]]
y1 y2
1 1 4
2 2 5
3 3 6
[[2]]
yA yB
1 1 4
2 2 5
3 3 6
How to save the modifications which *apply family of functions did on data?