How do you generate the sequence of numbers 1, 10, 100, 1000, 10000, ... quickly/efficiently in R?
I know seq
can give you a sequence of numbers separated by some interval, but is there a function that can give you powers of a number?
How to generate a power sequence of two in R? In R, for the calculation of power we can simply use power operator ^ and this will be also used in case of generating a power sequence. For example, if we want to generate a power sequence from 1 to 5 of 2 then we can use the code 2^ (1:5) this will result 2 4 8 16 32.
In R, for the calculation of power we can simply use power operator ^ and this will be also used in case of generating a power sequence. For example, if we want to generate a power sequence from 1 to 5 of 2 then we can use the code 2^ (1:5) this will result 2 4 8 16 32.
The seq () is a standard general with a default method to generate the sequence of numbers. To generate a sequence of numbers in R, use the seq () method. The seq () is an inbuilt R generic method that generates the regular sequences.
For example, if we want to generate a power sequence from 1 to 5 of 2 then we can use the code 2^ (1:5) this will result 2 4 8 16 32.
10^(0:10)
# [1] 1e+00 1e+01 1e+02 1e+03 1e+04 1e+05 1e+06 1e+07 1e+08 1e+09 1e+10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With