[R] as.matrix and one row
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Tue Mar 28 18:51:19 CEST 2006
Federico Calboli <f.calboli at imperial.ac.uk> writes:
> Hi All,
>
> I have the following problem:
>
> x = c(1,2)
> x
> [1] 1 2
>
> as.matrix(x)
> [,1]
> [1,] 1
> [2,] 2
>
> BUT, if I add:
>
> y = c(3,4)
>
> as.matrix(rbind(x,y))
> [,1] [,2]
> x 1 2
> y 3 4
>
> It does not transpose. Since I will need as.matrix() for a list of data
> that is in one or more lines, I need as.matrix to behave in a consisten
> fashions, so I get
Well, it's a NOP since the argument is a matrix already. R is not
"transposing" in the first case either, since the argument is not a
matrix. However, the convention is that vectors are treated as column
vectors, even though they print horisontally.
rbind(x) should get you to where you want soon enough.
> as.matrix(x, whatever)
> [,1] [,2]
> x 1 2
>
> and
>
> as.matrix(rbind(x,y), whatever)
> [,1] [,2]
> x 1 2
> y 3 4
>
> I tried byrow =T, does not make a thing.
>
> Regards,
>
> Federico Calboli
>
> --
> Federico C. F. Calboli
> Department of Epidemiology and Public Health
> Imperial College, St Mary's Campus
> Norfolk Place, London W2 1PG
>
> Tel +44 (0)20 7594 1602 Fax (+44) 020 7594 3193
>
> f.calboli [.a.t] imperial.ac.uk
> f.calboli [.a.t] gmail.com
>
> ______________________________________________
> 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
>
--
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