So I know I must be missing something simple and obvious for the following data manipulation where I have (in this example) 11 pairs of matrices (gs4.0 to gs4.100 and ps1.0 to ps1.100) from some population simulations (all with same dimensions) where I want to get some summary statistics on the products of the cells in a pair (e.g., gs4.0 * ps1.0). The code I wrote below works fine, but it seems like there ought to be a simple way to index the extensions on the names (.0 to .100) in a for loop to simplify this code greatly. I've spent some time trying various things using paste() and assign() and have had no success.
mean.comb <- as.matrix(0:10,nrow = 11, ncol=1) mean.comb <- cbind(mean.comb,0) ###to see list of files created gs4files <- ls(pattern="gs4.*0") ps1files <- ls(pattern="ps1.*0") mean.comb[1,2] <- mean(apply(gs4.0 * ps1.0,1,sum)) mean.comb[2,2] <- mean(apply(gs4.10 * ps1.10,1,sum)) mean.comb[3,2] <- mean(apply(gs4.20 * ps1.20,1,sum)) mean.comb[4,2] <- mean(apply(gs4.30 * ps1.30,1,sum)) mean.comb[5,2] <- mean(apply(gs4.40 * ps1.40,1,sum)) mean.comb[6,2] <- mean(apply(gs4.50 * ps1.50,1,sum)) mean.comb[7,2] <- mean(apply(gs4.60 * ps1.60,1,sum)) mean.comb[8,2] <- mean(apply(gs4.70 * ps1.70,1,sum)) mean.comb[9,2] <- mean(apply(gs4.80 * ps1.80,1,sum)) mean.comb[10,2] <- mean(apply(gs4.90 * ps1.90,1,sum)) mean.comb[11,2] <- mean(apply(gs4.100 * ps1.100,1,sum)) mean.comb<- data.frame(mean.comb) colnames(mean.comb) <- c("simulation", "mean.horses.removed") Brian Brian S. Cade, PhD U. S. Geological Survey Fort Collins Science Center 2150 Centre Ave., Bldg. C Fort Collins, CO 80526-8818 email: ca...@usgs.gov <brian_c...@usgs.gov> tel: 970 226-9326 [[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.