[R] R: vector to matrix transformation
Vito Ricci
vito_ricci at yahoo.com
Fri Dec 3 11:50:15 CET 2004
Hi,
did you see:
as.data.frame()
as.matrix()
as.vector()
matrix()
> x
a b c
1 1 2 3
2 1 2 3
3 2 3 4
4 3 4 5
> is.data.frame(x)
[1] TRUE
> as.matrix(x)
a b c
1 1 2 3
2 1 2 3
3 2 3 4
4 3 4 5
> y<-as.matrix(x)
> is.matrix(y)
[1] TRUE
> as.vector(y)
[1] 1 1 2 3 2 2 3 4 3 3 4 5
> z<-as.vector(y)
> m<-matrix(z,ncol=3)
> m
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 1 2 3
[3,] 2 3 4
[4,] 3 4 5
I hope I give you a little help.
Best
Vito
you 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 problem and I just gave up. Did anyone
knows how to transform a matrix into a vector and
back-transform a vector into a matrix?
Thanks by advance,
Gwenaël Jacob
=====
Diventare costruttori di soluzioni
Became solutions' constructors
"The business of the statistician is to catalyze
the scientific learning process."
George E. P. Box
Top 10 reasons to become a Statistician
1. Deviation is considered normal
2. We feel complete and sufficient
3. We are 'mean' lovers
4. Statisticians do it discretely and continuously
5. We are right 95% of the time
6. We can legally comment on someone's posterior distribution
7. We may not be normal, but we are transformable
8. We never have to say we are certain
9. We are honestly significantly different
10. No one wants our jobs
Visitate il portale http://www.modugno.it/
e in particolare la sezione su Palese http://www.modugno.it/archivio/palese/
More information about the R-help
mailing list