Re: [R] Dataframes: conditional calculations per row [SOLVED].

2009-02-09 Thread Jesús Guillermo Andrade
> Thank you very much Jorge, Phil and David: I was finally able to > perform the operations I needed. I changed the function in order to > adapt it to the simplest form like the following: > ali <- function(Abase) { > alitemp <- ((Abase/llmcc$Clase)*PClase)+(((1/llmcc > $Categoria)*Ab

Re: [R] Dataframes: conditional calculations per row .

2009-02-09 Thread David Winsemius
One way. there may be better. The apply function will work with just one row (or one column) at a time. > DF Month Week Estpassage MedFL 1 July 2766534 2 July 28 223235 3 July 29 924135 4 July 30 2846435 5Aug 31 4104935

Re: [R] Dataframes: conditional calculations per row .

2009-02-09 Thread jim holtman
You can use 'ifelse': > x <- data.frame(id=sample(1:4,20,TRUE)) > # use ifelse to do the calculations > x$cal <- ifelse(x$id == 1, 21, +ifelse(x$id == 2, 221, + ifelse(x$id == 3, 2221, 1))) > x id cal 1 4 1 2 121 3 3 2221 4 121 5 2 221 6