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
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
Dear List,
I'm wondering if there is a better/cleaner/more efficient way of
replacing 0 values in a variable with the minimum of the non-missing and
non-zero values of that same variable, but doing it within the levels of
a factor?
Consider the dummy example data presented at the end of my messag
3 matches
Mail list logo