Re: [R] Batch replacement, by factor, of values in a data frame

2009-08-26 Thread Gavin Simpson
On Wed, 2009-08-26 at 08:06 -0700, Phil Spector wrote: > The ave function is very handy for things like this: > > mins = ave(D$Var,D$Site,FUN=function(x)min(x[x>0],na.rm=TRUE)) > D$Var = ifelse(is.na(D$Var) | D$Var == 0,mins,D$Var) > > should do the required replacements. Thanks Phil, that's gre

Re: [R] Batch replacement, by factor, of values in a data frame

2009-08-26 Thread Phil Spector
The ave function is very handy for things like this: mins = ave(D$Var,D$Site,FUN=function(x)min(x[x>0],na.rm=TRUE)) D$Var = ifelse(is.na(D$Var) | D$Var == 0,mins,D$Var) should do the required replacements. - Phil Spector