Benjamin Tyner
2007-Aug-10 20:47 UTC
[Rd] suggestion with ambiguous object component replacement
?"[<-" says "When replacing (that is using indexing on the lhs of an assignment) NA does not select any element to be replaced. As there is ambiguity as to whether an element of the rhs should be used or not, this is only allowed if the rhs value is of length one (so the two interpretations would have the same outcome)." This is quite reasonable to me; for example, letters[NA] <- "z" does not throw an error but letters[NA] <- c("z","z") does. However I wonder why assignments like letters[c(2,2)] <- c("b1","b2") are allowed, since at least to me it is not clear at all that "b2" is the intended replacement. I would think that at the very least this should throw a warning. I apologize if this has already been discussed. Thanks Ben