[R] unexpected results
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Wed Jun 19 22:51:45 CEST 2002
"Niels Waller" <niels.waller at vanderbilt.edu> writes:
> Is R behaving correctly in this example? I do not understand why column 2
> has any 2s in it (and why column 3 has any 1s)
>
>
> > x<-matrix(0,10,3)
> > x[seq(1,10,by=2),2:3]<-c(1,2)
> > x
> [,1] [,2] [,3]
> [1,] 0 1 2
> [2,] 0 0 0
> [3,] 0 2 1
> [4,] 0 0 0
> [5,] 0 1 2
> [6,] 0 0 0
> [7,] 0 2 1
> [8,] 0 0 0
> [9,] 0 1 2
> [10,] 0 0 0
>
> Thank you for any and all help.
>
> (I am using 1.5.0 on Windows NT)
c(1,2) is recycled and the 5x2 submatrix is filled by column.
You might try
x[seq(1,10,by=2),2:3]<-matrix(c(1,2),5,2,byrow=T)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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