user702846 - 3 years ago 191
R Question

# dpylr how to summarize given multilevel grouping

I have a dataframe like

``````count  sample  type
1  DLF002     a
1  DLF002     a
1  DLF002     b
3  DLF001     a
3  DLF001     b
3  DLF001     b
``````

and would like to make a summary given two factor (sample and type), so I would like to have a result like the following

``````count  sample  type
2  DLF002     a
1  DLF002     b
3  DLF001     a
6  DLF001     b
``````

I have tried something like,

``````group_by(df, sample) %>% summarize(sx = sum(count)),
``````

but this does not into account the "type"; I wonder how I can make this two level grouping, using dpylr Remko Duursma
Simply add multiple grouping variables to `group_by`:
``````group_by(df, sample, type) %>% summarize(sx = sum(count))
{"ft_lang_label":"__label__en","ft_lang_prob":0.54173326,"math_prob":0.8928524,"size":333,"snap":"2020-34-2020-40","text_gpt3_token_len":116,"char_repetition_ratio":0.20668693,"word_repetition_ratio":0.1724138,"special_character_ratio":0.3873874,"punctuation_ratio":0.073529415,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9831602,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-23T02:34:26Z\",\"WARC-Record-ID\":\"<urn:uuid:3475f3a0-5f4d-4908-b8c5-de845e7ba86a>\",\"Content-Length\":\"44753\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:be4c1e15-3276-445a-b208-8c0f99a54cca>\",\"WARC-Concurrent-To\":\"<urn:uuid:3f46204e-673d-476e-82df-15b02ee0b07b>\",\"WARC-IP-Address\":\"72.52.219.43\",\"WARC-Target-URI\":\"https://codedump.io/share/w8zlqLSh5HuB/1/dpylr-how-to-summarize-given-multilevel-grouping\",\"WARC-Payload-Digest\":\"sha1:M4GYNJDKHLKHSTQGIAFA5YX4QYUQ6DVH\",\"WARC-Block-Digest\":\"sha1:WI7MX4EVTF6B2QMQ5AWJSTPGDX4SXQ2Z\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600400209665.4_warc_CC-MAIN-20200923015227-20200923045227-00316.warc.gz\"}"}