How can i generate a sequence of numbers which are in Geometric Progression in R? for example i need to generate the sequence : 1, 2,4,8,16,32 and so on....till say a finite value?
Here's what I'd do:
geomSeries <- function(base, max) {
base^(0:floor(log(max, base)))
}
geomSeries(base=2, max=2000)
# [1] 1 2 4 8 16 32 64 128 256 512 1024
geomSeries(3, 100)
# [1] 1 3 9 27 81