On Sat, 8 Jan 2011, Ron Michael wrote:

Hi, I have 2 questions on list object:
?
1. Suppose I have a matrix like:
dat <- matrix(1:9,3)
?
Now I want to replicate this entire matrix 3 times and put entire result in a list 
object. Means, if "res" is the resulting list then I should have:
?
res[[1]]=dat, res[[2]]=dat, res[[3]]=dat
?
How can I do that in the easilest manner?

See

        ?rep
        ...
        Examples
        ...
        ## replicate a list
        ...

?
2. Suppose I have 2 list objects:
list1 <- list2 <- vector("list", length=2)
for(i in 1:2) {
??list1[[i]] <- matrix(rnorm(15), 3)
??list2[[i]] <- matrix(rnorm(15), 3)
?}

How can I add these 2 list objects? I have tried with just list1+list2, however 
it is generating some error.
?

See

        ?mapply

        take note of the SIMPLIFY arg, which you want as FALSE

HTH,

Chuck


Would be grateful for any help.
?
Thanks,


        [[alternative HTML version deleted]]



Charles C. Berry                            Dept of Family/Preventive Medicine
cbe...@tajo.ucsd.edu                        UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

______________________________________________
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.

Reply via email to