Skip to content
Back to formatted view

Raw Message

Message-ID: <loom.20111026T135230-394@post.gmane.org>
Date: 2011-10-26T11:53:13Z
From: Ben Bolker
Subject: New column of data filled with the larger value from 2 columns

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)))