Re: [R] Vector to Matrix transformation

From: talepanda <talepanda_at_gmail.com>
Date: Wed 24 Jan 2007 - 08:58:50 GMT

non-elegant solution:

matrix(c(V1,rep(NA,-length(V1)%%5)),nrow=5)

HTH. On 1/24/07, Shubha Vishwanath Karanth <shubhak@ambaresearch.com> wrote:
> How to suppress the recycling of items in a matrix..instead NA can be
> filled.
> -----Original Message-----
> From: Chuck Cleland [mailto:ccleland@optonline.net]
> Sent: Tuesday, January 23, 2007 8:00 PM
> To: Shubha Vishwanath Karanth
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] Vector to Matrix transformation
>
> 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?
>
> You could try the following:
>
> matrix(V1, nrow=5)
>
> but note what happens when the length of V1 is not a multiple of 5.
>
> > Thanks in advance...
> >
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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.
>
> --
> Chuck Cleland, Ph.D.
> NDRI, Inc.
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 845-4495 (Tu, Th)
> tel: (732) 512-0171 (M, W, F)
> fax: (917) 438-0894
>
> ______________________________________________
> R-help@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.
>



R-help@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. Received on Wed Jan 24 20:03:55 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 24 Jan 2007 - 10:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.