Hello: # some code to assign with and without "which" q <- 1:20; q[c(9, 12, 14)] <- NA r <- 1:20; r[c(8:9, 12:15)] <- NA s <- 1:20; s[c(8:9, 12:15)] <- NA r[q < 16] <- 0 s[which(q < 16)] <- 0 r;s # both: 0 0 0 0 0 0 0 0 NA 0 0 NA 0 NA 0 16 17 18 19 20 r <- 1:20; r[c(8:9, 12:15)] <- NA s <- 1:20; s[c(8:9, 12:15)] <- NA r[is.na(q)] <- 30 s[which(is.na(q))] <- 30 r;s # both: 1 2 3 4 5 6 7 NA 30 10 11 30 NA 30 NA 16 17 18 19 20
So it appears to me that "a[b] <- c" delivers the same results as a[which(b)] <- c". Is there any situation where the assignment with/ out which indeed makes a difference?
Thanks for help Regards Sören ______________________________________________ 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.