Re: [R] Apply pmax to dataframe with different args based on dataframe factor

2012-02-10 Thread Idris Raja
damn, that's pretty clever. +1 thanks On Thu, Feb 9, 2012 at 8:11 PM, ilai wrote: > Your attempt was just overly complicated. All you needed was > > threshold <- c( .2 , .4 , .5 )[ df$track ] > df$value <- pmax(threshold, df$value) > df # desired outcome > > Cheers > > On Thu, Feb 9, 2012 at 3:

Re: [R] Apply pmax to dataframe with different args based on dataframe factor

2012-02-09 Thread ilai
Your attempt was just overly complicated. All you needed was threshold <- c( .2 , .4 , .5 )[ df$track ] df$value <- pmax(threshold, df$value) df # desired outcome Cheers On Thu, Feb 9, 2012 at 3:56 PM, Idris Raja wrote: > # I have a dataframe in the following form: > > track <- c(rep('A', 3), r

[R] Apply pmax to dataframe with different args based on dataframe factor

2012-02-09 Thread Idris Raja
# I have a dataframe in the following form: track <- c(rep('A', 3), rep('B', 4), rep('C', 4)) value <- c(0.15, 0.25, 0.35, 0.05, 0.99, 0.32, 0.13, 0.80, 0.75, 0.60, 0.44) df <- data.frame(track=factor(track), value=value) #> print(df) #track value #1 A 0.15 #2 A 0.25 #3 A 0.3