'How to generate a v shaped sequence in R without using cbind

I'm working through r-exercises. One requires generating the following vector:

[0.05, 0.5, 5.0, 0.5, 0.05]

The catch is cbind or loops cannot be used.

Here is what I tried:

rep(0.05 * 10^(seq(0,2)), times=2)

But of course that just returns:

[1] 0.05 0.50 5.00 0.05 0.50 5.00

Any ideas?

r


Solution 1:[1]

You can apply abs to a sequence centered at 0 to symmetrize it:

5*10^-abs(-2:2)
## [1] 0.05 0.50 5.00 0.50 0.05

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mikael Jagan