On Sat, 2007-09-15 at 12:11 -0400, Letticia Ramlal wrote:
> Hello 
> I was wonderinf if anyone can help me with this problem, it seems trivial but 
> for some reason I can not figure it out.
>  
> With a single R command complete the following:
> create a vector calles seqvec that repeats the sequence 1, 3,6, 10,15,21.( I 
> was trying to use c() but this does not work) 
> create a 5-row, 6-column matirx from seqvec wuth each row containg the 
> sequence from before 
> and complete the two task above in a single step.
>  
> LTR

Is this what you want?

seqvec <- cumsum(1:6)

> seqvec
[1]  1  3  6 10 15 21


Or to address both:

> matrix(rep(cumsum(1:6), 5), ncol = 6, byrow = TRUE)
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    3    6   10   15   21
[2,]    1    3    6   10   15   21
[3,]    1    3    6   10   15   21
[4,]    1    3    6   10   15   21
[5,]    1    3    6   10   15   21


See ?cumsum and ?rep

HTH,

Marc Schwartz

______________________________________________
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