Re: [R] manipulating elements of a vector

About this list Date view Thread view Subject view Author view Attachment view

From: Peter Dalgaard (p.dalgaard@biostat.ku.dk)
Date: Thu 27 May 2004 - 20:27:44 EST


Message-id: <x2isei2mhr.fsf@biostat.ku.dk>


"Vumani Dlamini" <dvumani@hotmail.com> writes:

> Dear R users;
>
> I would like to convert a series of vectors to matrices in the
> following way;
> (2,1,1) to a matrix
> 1 0 0
> 1 0 0
> 0 1 0
> 0 0 1
>
> The idea is that the column sum of the matrix should be equal to the
> elements of the vector.

Didn't we just do that? (No, that was incidence matrices...)
  
  i <- rep(1:3,c(2,1,1))
  diag(3)[i,]

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:13 EST