Re: [R] Using if and else in a data frame

2012-04-26 Thread Rui Barradas
Hello, Your example code has a bug, there's no fata.frame called 'AB'. It's corrected below. pannigh wrote > > Dear list, > I get the ifelse function to work on a data frame but don't know how to do > something similar (only more conditions) with the combination of if and > else like in the exa

[R] Using if and else in a data frame

2012-04-26 Thread pannigh
Dear list, I get the ifelse function to work on a data frame but don't know how to do something similar (only more conditions) with the combination of if and else like in the example: A <- c("a","a","b","b","c","c") B <- c(rep(2,6)) dat <- data.frame(A,B) dat$C <- if(AB$A=="a") {AB$B^2} else