Re: [R] data frame question

From: Mark Wardle <>
Date: Sun, 10 Feb 2008 20:44:17 +0000

On 10/02/2008, joseph <> 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

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 10 Feb 2008 - 20:47:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 10 Feb 2008 - 21:30:13 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive