Thank you, that worked great!

Sean


Peter Alspach wrote:
Tena koe Sean

I suspect the apply() and merge() functions are working, but they may
not be doing what you expect :-)  You could try rbind() and aggregate():

data.frame1$HAD <- as.numeric(NA)
data.both <- rbind(data.frame1, data.frame2)
aggregate(data.both[,-(1:3)], data.both[,1:3], sum, na.rm=T)
  Season   Gear Area COD POLL HAD
1 winter dredge  515 113  174  18

This assumes COD, POLL and HAD are numeric.

HTH ....

Peter Alspach
-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sean M. Lucey
Sent: Thursday, 21 January 2010 9:20 a.m.
To: r-help@r-project.org
Subject: [R] Merge and join data

Hi,

I'm looking to combine two data frames. Several of the columns are in common while the others need to be summed up. The apply functions and the merge functions don't seem to be working. I've included a basic example of what I'm trying to do below. Thanks!

Sean


data.frame1<-as.data.frame(matrix(c('winter','dredge','515',10
0,150),1,5))
names(data.frame1)<-c('Season','Gear','Area','COD','POLL')

data.frame2<-as.data.frame(matrix(c('winter','dredge','515',13
,24,18),1,6))
names(data.frame2)<-c('Season','Gear','Area','COD','POLL','HAD')


I'd like to end up with something that looks like this:

Season   Gear   Area   COD   POLL   HAD
winter   dredge   515    113      174      18

Thanks,
Sean


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to