o:[EMAIL PROTECTED]
> 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 len
How to suppress the recycling of items in a matrix..instead NA can be
filled.
-Original Message-
From: Chuck Cleland [mailto:[EMAIL PROTECTED]
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
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?
check the help page for ?matrix(); you probably want either
matrix(V1, nrow = 5)
or
matrix(V1, nrow = 5, byrow = TRUE)
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 3
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
If v is a vector, as.matrix(v) and t(v) give row and column
matrices and matrix(v,nrow=nr, ncol=nc) gives a matrix with
nr rows and nc columns such that the vector fills the first
column, then the second, etc. You only have to provide nr
or nc in most cases.
If m is a matrix c(m) is a vector
In addition to Sean's reply look at ?dist and other ways of creating
distance / similarity matrices for applications like Mantels Test. Package
vegan might be particularly useful.
HTH, Andy
R > x <- rnorm(10)
R > y <- dist(x)
R > str(x)
num [1:10] -0.431 0.564 0.901 -1.407 -0.991 ...
R > str(y
On 3 Dec 2004 at 11:39, Gwenael Jacob wrote:
> Dear,
>
> Some analysis (linear regression) can only be
> done from a vectorized dataset whereas others
> require a matrix (Mantel tests). I use the two
> analyses and thus need to format my data in
> matrix and vector. I spent some time trying
On Dec 3, 2004, at 5:39 AM, Gwenael Jacob wrote:
Dear,
Some analysis (linear regression) can only be done from a vectorized
dataset whereas others require a matrix (Mantel tests). I use the two
analyses and thus need to format my data in matrix and vector. I spent
some time trying to solve the p