[R] abbreviate
    Marc Schwartz 
    MSchwartz at mn.rr.com
       
    Wed Jun 15 20:33:43 CEST 2005
    
    
  
On Wed, 2005-06-15 at 13:59 -0400, Omar Lakkis wrote:
> > p = data.frame(high=c(5,2), settle=c(3,4))
> > p
>   high settle
> 1    5      3
> 2    2      4
> 
> What is the most abbreviated way to apply:
> if (p$high < p$settle) p$high = p$settle
> 
> I want to modify p to become:
> > p
>   high settle
> 1    5      3
> 2    4      4
Probably the easiest would be:
> p
  high settle
1    5      3
2    2      4
> p$high <- with(p, ifelse(high < settle, settle, high))
> p
  high settle
1    5      3
2    4      4
See ?ifelse and ?with
HTH,
Marc Schwartz
    
    
More information about the R-help
mailing list