[R] line up a matrix
John Fox
jfox at mcmaster.ca
Fri Jan 4 17:19:01 CET 2002
Dear Tord,
At 02:32 PM 1/4/2002 +0100, Tord Snall wrote:
>I try to rearrange my ref. database (now in Excel!! :( ) for importing it
>into a reference manager program (RIS format).
>
>My file basically look like this [3,4]-matrix:
>
>rbind(c("a", "b", "c", "d"), c("e", "f", "g", "h"), c("i", "j", "k", "l"))
> [,1] [,2] [,3] [,4]
>[1,] "a" "b" "c" "d"
>[2,] "e" "f" "g" "h"
>[3,] "i" "j" "k" "l"
>
>and I have tried to find a function to line up the matrix into a vector
>which I would like to look like this:
>
>t(c("a", "b", "c", "d","e", "f", "g", "h","i", "j", "k", "l"))
>
>Is there any R function for available for that?
Matrices are stored column-wise, so try
> mat <- rbind(c("a", "b", "c", "d"), c("e", "f", "g", "h"),
c("i", "j", "k", "l"))
> as.vector(t(mat))
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"
If you really want a one-column matrix, as your question seems to imply,
you could use
> matrix(t(mat), ncol=1)
[,1]
[1,] "a"
[2,] "b"
[3,] "c"
[4,] "d"
[5,] "e"
[6,] "f"
[7,] "g"
[8,] "h"
[9,] "i"
[10,] "j"
[11,] "k"
[12,] "l"
I hope that this helps,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list