I have a list of 12 data.frames:
m =list(X2016_kvish_1_10t, X2015_kvish_1_10t, X2014_kvish_1_10t,
X2013_kvish_1_10t, X2012_kvish_1_10t, X2011_kvish_1_10t,
X2010_kvish_1_10t, X2009_kvish_1_10t, X2008_kvish_1_10t)
X2007_kvish_1_10t, X2006_kvish_1_10t, X2005_kvish_1_10t)
and I have a list of 12 vectors called mean_values
. Output from str(mean_values)
:
List of 12
$ : Named num [1:168] 2848 2848 2848 2848 2848 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 2870 2870 2870 2870 2870 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 2911 2911 2911 2911 2911 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 3422 3422 3422 3422 3422 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : NULL
$ : Named num [1:168] 2747 2747 2747 2747 2747 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 3234 3234 3234 3234 3234 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 3334 3334 3334 3334 3334 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 3440 3440 3440 3440 3440 3440 3440 3440 3440 3440 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 3327 3327 3327 3327 3327 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 3440 3440 3440 3440 3440 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
$ : Named num [1:168] 3497 3497 3497 3497 3497 ...
..- attr(*, "names")= chr [1:168] "a" "a" "a" "a" ...
I need to add each vector to new column in each data.frame from the list. when I do separately it works well:
X2016_kvish_1_10t$mean_values = mean_values[[1]]
X2016_kvish_1_10t$mean_values = mean_values[[2]]
X2016_kvish_1_10t$mean_values = mean_values[[3]]
# ... until 12
but I need to find a way to add these vectors in one shot. I tried this function:
for(i in 1:length(m)){m[[i]]$means = mean_values[[i]]}
this function works great but only when I print the whole list of the dataframes. I need to find a way to apply the changes to the originals dateframes, each one s.