[R] New column of data filled with the larger value from 2 columns

Ben Bolker bbolker at gmail.com
Wed Oct 26 13:53:13 CEST 2011


robgriffin247 <robgriffin247 <at> hotmail.com> writes:

> 
> Hi,
> I'm sure there is a pretty simple answer to this but I have had my head
> buried in the R book and on help pages for a while now and I've not made any
> progress.
> 
> In simple terms:
> I have 2 columns of data, column A and column B. I want to create a new
> column (C) and fill it with the largest value from of A or B on each row.
> 

  sounds like you want data$C <- pmax(data$A,data$B)
(or data <- transform(C,pmax(A,B)))



More information about the R-help mailing list