[R] aggregate and sum on some columns fromduplicate rows

ltdm Luis.Tito-de-Morais at ird.fr
Sat Mar 1 00:01:56 CET 2014


Hi again,

Sorry for disturbing. After posting I suddenly found a solution.
As it may help someone else here it goes.

df
du1 <- duplicated(df[,c("St.Sam","Species")],fromLast = F)
du2 <- duplicated(df[,c("St.Sam","Species")],fromLast = T)
X <- df[du1|du2,]
aggRows <- aggregate(cbind(NT,PT) ~St.Sam+Species+Var1+Var2, X,sum)
dfNew <- rbind(df[!(du1|du2),], aggRows)

Just need to "polish" dfNew and its OK. But maybe there is a more elegant
solution.

Cheers,

Tito





--
View this message in context: http://r.789695.n4.nabble.com/aggregate-and-sum-on-some-columns-fromduplicate-rows-tp4686040p4686043.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list