Hi All: I'm looking to find out a bit more about how subassignment actually works and am hoping someone with knowledge of the details can fill me in (I've looked at the source code, but my knowledge of C is lacking). In the case of vectors, my reading of ?"[" would indicate that for a vector, vec <- 1:25, vec[c(1,5,25)] <- c(101,102,103)is functionally the same as indx <- c(1,5,25) for (i in 1:length(indx)) vec[indx[i]] <- c(101,102,103)[i] And in the case of a data frame, df <- data.frame(d1=1:10,d2=11:20,d3=21:30), df[c(1,5,10),c(1,3)] <- data.frame(a=101:103,b=104:106)is functionally the same as rowindx <- c(1,5,10) colindx <- c(1,3) for (i in 1:length(rowindx)) { for (j in 1:length(colindx)) df[rowindx[i],colindx[j]] <- data.frame(a=101:103,b=104:106)[i,j] } Obviously I've verified that these examples work and I realize that my loops also contain subassignments; what I'm really after is to understand the mechanics of replacing multiple elements. Is a for-loop the proper way to understand the sequential nature of subassignments here (even if it is not actually implemented using a loop)? Cheers,HR [[alternative HTML version deleted]]
______________________________________________ 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.