[R] Odd subsetting behaviour

math_daddy math_daddy at hotmail.com
Tue Jul 6 19:57:23 CEST 2010


Hello. I've observed some odd behaviour. Most likely, it is already known and
explained somewhere, but I can't find an explanation anywhere, so I would
appreciate being pointed in the right direction.

The issue with the following code is self explanatory:

> mat <- matrix(c(c(1,1,1),c(2,2,2)),nrow=3)
> mat[,c(1:3%/%2)]
     [,1] [,2]
[1,]    1    1
[2,]    1    1
[3,]    1    1
> n <- 3%/%2
> mat[,c(1:n)]
[1] 1 1 1

What I want to know is, why does it give the first column twice when 3%/%2
is computed within the subset call, and just the first row when it is
computed outside?

Thanks very much in advance.
-- 
View this message in context: http://r.789695.n4.nabble.com/Odd-subsetting-behaviour-tp2279957p2279957.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list