Skip to content
Prev 257878 / 398502 Next

If Then Trouble

On 24.04.2011 22:10, Sparks, John James wrote:
See help("if") and find if(foo) is only designed for scalar values of 
foo. You actually want to use:

if(testY2$redgroups>17) testY2$redgroups<-17

testY2$redgroups[testY2$redgroups > 17] <- 17

or using some less efficient "if"-like statement:

testY2$redgroups <- ifelse(testY2$redgroups > 17, 17, testY2$redgroups)


Uwe Ligges