Fox, Gordon <gfox <at> cas.usf.edu> writes: > Example: 40 and 80 have these factors: c(1,2,2,2,5) and c(1,2,2,2,2,5). > We can use match() to get the common factors c(1,2,2,2,5). What we want > to be able to get from this is the list of all the possible products, > which should be the concatenation of the original list, the products of > all the pairs, of all the triplets, and so forth: > c(1,2,2,2,5,4,8,10,20,40).
This is somewhat brute force, but how about commfac <- c(1,2,2,2,5) cfun <- function(i) { combn(commfac,i,prod) } L <- lapply(as.list(1:length(commfac)),cfun) unique(sort(unlist(L))) ? Ben Bolker ______________________________________________ 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.