I have a list of isometric structures, and I want to change the same
part of each structure in the list, assigning one element of a vector to
each of these parts.
In other words, I want to achieve the following:
> l <- list( list(a=1,b=2), list(a=3,b=4))
> unlist(lapply(l, "[[", "a"))
[1] 1 3
>
> # This will not actually work
> l[[]]["a"] <- 5:6
>
> unlist(lapply(l, "[[", "a"))
[1] 5 6
I figure mapply is the solution to the problem, and I tried the following:
> mapply( "[<-", l, "a", 5:6)
But the result is not the same shape as the original.
Any thoughts?
Best,
Magnus
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.