如何使数列升为幂数

时间:2019-06-17 13:31:53

标签: r sequence seq

我有:

cost = c(2^(-5),2^(-3),2^(-1),2^(1),2^(3),2^(5),2^(7),2^(9),2^(11),2^(13),2^(15))

,我想要一个更优雅的命令,例如:

seq(from = 2^(-5), to = 2^(15), by = __)

1 个答案:

答案 0 :(得分:5)

^在两个参数中都是向量化的,因此您可以将2提升为很好的线性幂序列:

2^seq(from = -5, to = 15, by = 2)