r - Count observations of distinct values per group and add a new column of counts for each value -


this question has answer here:

similar question count number of observations/rows per group , add result data frame not quite.

i'd transform this

   group id_in_group letter 1:              a1   alef 2:              a2    bet 3:              a3    bet 4:     b          b1   alef 5:     b          b2   alef 6:     b          b3  gimel 

into this

   group aleph bet gimel 1:         1   2     0 2:     b     2   0     1 

or without additional library, can use table:

table(df$group,df$letter) 

as seem work data.table, can use dcast()

dcast(df, group~letter,length) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -