Skip to content
Back to formatted view

Raw Message

Message-ID: <b59a37130802101244k25262e48gd5968d6a77483537@mail.gmail.com>
Date: 2008-02-10T20:44:17Z
From: Mark Wardle
Subject: data frame question
In-Reply-To: <109232.80965.qm@web36905.mail.mud.yahoo.com>

On 10/02/2008, joseph <jdsandjd at yahoo.com> wrote:
> Hello
> I have 2 data frames df1 and df2. I would like to create a
> new data frame new_df which will contain only the common rows based on the first 2
> columns (chrN and start). The column score in the new data frame
> should
> be replaced with a column containing the average score (average_score) from df1
> and df2.


Try this:   (avoiding underscores)

new.df <- merge(df1, df2, by=c('chrN','start'))
new.df$average.score <- apply(df3[,c('score.x','score.y')], 1, mean, na.rm=T)

As always, interested to see whether it can be done in one line...

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK