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 22, 2016 at 11:34 AM, Dimitri Liakhovitski <dimitri.liakhovit...@gmail.com> wrote: > 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 Liakhovitski -- Dimitri Liakhovitski ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.