[R] Vector to Matrix transformation

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Jan 23 15:28:03 CET 2007


Shubha Vishwanath Karanth wrote:
> Hi R,
>
>  
>
> I have a vector V1 of unknown length, say n. I need to convert this into
> a matrix C of row size=5, and accordingly the column should be updated.
> I tried with:
>
>  
>
> C=as.matrix(V1,5,n/5)
>
>  
>
> But it is not working...Could somebody help me on this?
matrix(), not as.matrix()

The help page for as.matrix displays quite clearly that as.matrix takes
only a single argument x.

You can also set the dimensions using dim(V1) <- c(5, n/5)

>  
>
> Thanks in advance...
>
>  
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>   


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list