[R] lapply / mapply and assignments
Magnus Torfason
zulutime.net at gmail.com
Tue Oct 13 15:19:30 CEST 2009
Thank you so much, relist and SIMPLIFY both work.
See more comments below ...
On 10/12/2009 5:35 PM, Charles C. Berry wrote:
> On Mon, 12 Oct 2009, Magnus Torfason wrote:
>> I want to achieve the following:
>>
>>> l <- list( list(a=1,b=2), list(a=3,b=4))
>>> l[[]]["a"] <- 5:6
>
> See
> ?relist
>
> something like:
>
> relist( unlist( mapply( "[<-", l, "a", 5:6) ), l )
Yes, this works exactly as needed. I had tried this, but I failed to
notice that you could supply the skeleton argument separately. Thanks!
I had also tried
mapply( "[<-", l, "a", c(5,6), SIMPLIFY=FALSE)
but failed to put SIMPLIFY in all-caps, and got an error message that I
did not understand. It seems I was close on both methods, but not close
enough.
Best,
Magnus
More information about the R-help
mailing list