[R] how to replace NA with a specific score that is dependant on another indicator variable

2010-09-01 Thread Chris Howden
Hi everyone, I’m looking for a clever bit of code to replace NA’s with a specific score depending on an indicator variable. I can see how to do it using lots of if statements but I’m sure there most be a neater, better way of doing it. Any ideas at all will be much appreciated, I’m dreadin

Re: [R] how to replace NA with a specific score that is dependant on another indicator variable

2010-09-01 Thread Hadley Wickham
> first ddply result did I see that some sort of misregistration had occurred; > Better with: > > res <-ddply(egraw2, .(category), .fun=function(df) { >               sapply(df, >                    function(x) {mnx <- mean(x, na.rm=TRUE); >                                 sapply(x, function(z) if

Re: [R] how to replace NA with a specific score that is dependant on another indicator variable

2010-09-01 Thread David Winsemius
On Sep 1, 2010, at 10:19 AM, David Winsemius wrote: On Sep 1, 2010, at 9:55 AM, David Winsemius wrote: On Sep 1, 2010, at 9:20 AM, Chris Howden wrote: Hi everyone, I’m looking for a clever bit of code to replace NA’s with a specific score depending on an indicator variable. I can s

Re: [R] how to replace NA with a specific score that is dependant on another indicator variable

2010-09-01 Thread David Winsemius
On Sep 1, 2010, at 9:55 AM, David Winsemius wrote: On Sep 1, 2010, at 9:20 AM, Chris Howden wrote: Hi everyone, I’m looking for a clever bit of code to replace NA’s with a specific score depending on an indicator variable. I can see how to do it using lots of if statements but I’m sur

Re: [R] how to replace NA with a specific score that is dependant on another indicator variable

2010-09-01 Thread David Winsemius
On Sep 1, 2010, at 9:20 AM, Chris Howden wrote: Hi everyone, I’m looking for a clever bit of code to replace NA’s with a specific score depending on an indicator variable. I can see how to do it using lots of if statements but I’m sure there most be a neater, better way of doing it.

Re: [R] how to replace NA with a specific score that is dependant on another indicator variable

2010-09-01 Thread Chris Howden
Hi everyone, I’m looking for a clever bit of code to replace NA’s with a specific score depending on an indicator variable. I can see how to do it using lots of if statements but I’m sure there most be a neater, better way of doing it. Any ideas at all will be much appreciated, I’m dreadin