This is, no doubt, an easy problem, but I need help. I want to set values in a matrix based on entries in a vector. Here is an example: D is an r x m matrix initilized to all zeroes. r=6, m=5 in the example. Ro <- c(1, 3, 4, 4, 6) Co <- c(1, 2, 3, 4, 5) I want to set D[Ro[j], Co[j] ] to 1. So, D becomes 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 A loop works but is slow, which matters since this is being done many times in a simulation. Thanks, rv
[[alternative HTML version deleted]] ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html