[R] unexpected results

Huntsinger, Reid reid_huntsinger at merck.com
Wed Jun 19 22:58:40 CEST 2002


Yes, that's correct behavior. You are assigning to an extracted submatrix,
and what you're assigning is a vector of length two. This gets "recycled" to
the correct length, which is ten, and fills the submatrix *column-by-column*
(column-major order). 

You probably wanted to iterate x[i,2:3] <- c(1,2) over i. You could use
"rep" to construct the vector like

x[seq(1,10,by=2), 2:3] <- rep(c(1,2),c(5,5))

to get this effect.

Reid Huntsinger



-----Original Message-----
From: Niels Waller [mailto:niels.waller at vanderbilt.edu]
Sent: Wednesday, June 19, 2002 4:26 PM
To: R-Help
Subject: [R] unexpected results




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)

Niels Waller

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message.  If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.

==============================================================================

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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