I spent some time on this simple question, also searched the forum, eventually hacked my way to an ugly solution for my particular problem but I would like to improve my coding:
I have data of the form: df <- expand.grid(group=c('copper', 'zinc', 'aluminum', 'nickel'), condition1=c(1:4)) I would like to add a new data column "condition2", with values equal to the value of condition1 plus a random number from 0-1 (uniform distribution) if the value of condition1 is < 1, or just condition1 if the value of condition1 is > 1. More generally, my interest is in manipulating the values of condition1 if they meet one or more criteria, or keeping the values the same otherwise. Thanks for any thoughts! -- View this message in context: http://r.789695.n4.nabble.com/Performing-operations-only-on-selected-data-tp4650646.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list 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.