Re: [R] Shift all values above certain value by 1

2016-01-23 Thread jim holtman
You can keep it a dataframe as follows: > set.seed(123) > x <- data.frame(a = 1:10, b = 2:11, c = 3:12, other = rnorm(10)) > x a b c other 1 1 2 3 -0.56047565 2 2 3 4 -0.23017749 3 3 4 5 1.55870831 4 4 5 6 0.07050839 5 5 6 7 0.12928774 6 6 7 8 1.71506499 7

Re: [R] Shift all values above certain value by 1

2016-01-22 Thread Dimitri Liakhovitski
I think I got it: set.seed(123) x <- data.frame(a = 1:10, b = 2:11, c = 3:12, other = rnorm(10)) x temp <- as.matrix(x[1:3]) temp[temp %in% 7] <- 4 temp[temp > 7] <- temp[temp > 7]-1 x[1:3] <- temp x It works only with matrices, right? Can't do x[x>7] when x is a data frame? Thanks! On Fri, Jan

[R] Shift all values above certain value by 1

2016-01-22 Thread Dimitri Liakhovitski
Hello! # I have a data frame x: x <- data.frame(a = 1:10, b = 2:11, c = 3:12, other = rnorm(10)) # First, I need to change every value 7 in columns a:c to 4 # Then, I need to decrease by 1 all values in columns a:c that are >7 What would be the fastest way of doing it? Thank you! -- Dimitri