[R] merge dataframes with condition

Geophagus
Thu, 15 Nov 2012 14:47:40 -0000

Hi @ all,
I wamnt to combine two dataframes including a condition.
I have  two dataframes like the following:

animal<-c("bear","bear","lion","monkey","fish","monkey","bear","zebra","zebra")
val<-c(2,42,67,5,12,9,87,1,12)
place<-c("S","N","N","Z","R","O","E","I","Q")
df1<-data.frame(animal,val,place)
animal<-c("bear","bear","lion","monkey","fish","monkey","bear","zebra","zebra")
val<-c(21,45,78,6,18,77,89,17,28)
place<-c("S","N","N","Z","R","G","O","P","Q")
df2<-data.frame(animal,val,place)

I would like to merge them with a condition. If "animal" and
"place" are
eqal in both df's, then add the values.
If not add all three parameters
("animal","value","place") at the bottom
(like rbind).

I hope somebody can help me.
Thank a lot.
geo




--
View this message in context: