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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -