[R] looking for .. dec if vector if element > x

Adrian Dusa dusa.adrian at gmail.com
Tue May 18 15:35:13 CEST 2010


On Tuesday 18 May 2010, Knut Krueger wrote:
> Hi to all,
> I am just looking for more efficient ways ;-)
> 
> is there a better way instead a loop  to decrease x if greater y
> test  <- c(1,3,5,7,9)
> 
> decrease if greater 1 to
> test2  <- c(1,2,4,6,8)

Does this help?

> test  <- c(1, 3, 5, 7, 9)
> test[test > 1] <- test[test > 1] - 1
> test
[1] 1 2 4 6 8

Adrian

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
     +40 21 3120210 / int.101
Fax: +40 21 3158391



More information about the R-help mailing list