I have data that looks like this.
    Weight     Zip
    23         88762
    45.3       34957
    37.6       87293
    212.45     34957
    58.3       87293
    92.45      88762
I am trying to sum the weights that correspond to the same zip code and add the result to a new column:
    TotalWeight
    115.45
    257.75
    95.9
    257.75 
    95.9 
    115.45
I thought about doing something like this but I figure there must be something more efficient. Thanks!
weight <- c(23, 45.3, 37.6, 212.45, 58.3, 92.45)
zip <- c(88762L, 34957L, 87293L, 34957L, 87293L, 88762L)
function(){
zippop<-data.frame()
for (i in unique(zip)){
zippop<-rbind(zippop, c(i,sum(weight[which(zip==i)])))}
return (zippop)
}