[R] Sign of specific elements of a vector
Frank S.
f_j_rod at hotmail.com
Thu Jun 18 21:40:59 CEST 2015
Hi everyone,
I have an "x" vector and I would want to change the sign every 20 elements. For this puspose,
I wrote the following code:
set.seed(1)
x <- rnorm(100)
x
x[seq(20,100, by=20)] <- -x[seq(20,100, by=20)]
x
However, I'm afraid it is a rudimentary form to get the desired result. II wonder wether there is a cool way to do so, that is, for example with apply or sign function.
Thans in advanced for your help!
Frank S.
[[alternative HTML version deleted]]
More information about the R-help
mailing list