math_daddy wrote:
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?


Hint:

Look at

c(1:3 %/% 2)

It's an Order of Operations Thing.

See ?Syntax

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to