Hi,
  I was playing with some code and came upon this situation.

> x <- c(1, rep(0,9))
> x
 [1] 1 0 0 0 0 0 0 0 0 0
> idx <- 1:10
> x[idx] <- x[idx] + 1
> x
 [1] 2 1 1 1 1 1 1 1 1 1

This is expected. But if I do:

> x <- c(1, rep(0,9))
> x
 [1] 1 0 0 0 0 0 0 0 0 0
> idx <- rep(0,10)
> idx
 [1] 0 0 0 0 0 0 0 0 0 0
> x[idx] <- x[idx] +1
> x
 [1] 1 0 0 0 0 0 0 0 0 0

I was expoecting that when all the elements of idx are set to 0,
x[0] would become 11.

Could somebody explain why this behavior occurs?

Thanks,


-------------------------------------------------------------------
Rajarshi Guha <[EMAIL PROTECTED]> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
A computer lets you make more mistakes faster than any other invention,
with the possible exceptions of handguns and Tequilla.
-- Mitch Ratcliffe

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to