# NOT RUN {
## Generate some random data
set.seed(33550336)
mySamp <- sample(10^5, 5*10^4)
## Quickly generate complete factorizations up
## to 10^5 (max element from mySamp)
system.time(allFacs <- divisorsList(10^5))
## Use generated complete factorization for further
## analysis by accessing the index of allFacs
for (s in mySamp) {
myFac <- allFacs[[s]]
## Continue algorithm
}
## Generating the complete factorization on the fly is much slower.
## See below for a couple of examples that are not as efficient.
# }
# NOT RUN {
## Brute Force... very slow
system.time(mySampFacs <- lapply(mySamp, function(x) (1:x)[x%%(1:x)==0L]))
## Using numbers::divisors... better than brute force, but still
## much slower than calling divisorList
system.time(mySampFacs <- lapply(mySamp, function(x) numbers::divisors))
# }
Run the code above in your browser using DataLab