R create a column based on duplicate values of one column, and a second column -


i have 2 columns. 1 has several duplicate values (col a) (like 10, 10, 20, 5, 10, 20, etc...). other (col b) binary (0/1) variable. need r first sort first column a, if necessary, , @ duplicate values, , corresponding values in second column, b. then, each set of duplicate values in col a, need sum values in col b. so, if there 5 10s in col a, need sum 1s in col b associated each of these 5 10s.

how do this?

thanks.

you want aggregation:

aggregate(b~a, df, fun=sum) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -