dataframe - r data.table summarizing using more than one factor -


i have below data.table

'data.frame':   66977 obs. of  16 variables:  $ subs                         : int    $ city                         : factor w/ 18 levels   $ value_seg                    : factor w/ 7 levels   $ region                       : factor w/ 5 levels   $ sum.data_ppu_rev_dec.        : num    $ sum.data_bundle_rev_dec.     : int    $ sum.data_usage_total_kb_dec. : num    $ sum.this_month_rev_dec.      : num    $ sum.voice_onnet_duration_dec.: num    $ sum.voice_onnet_rev_dec.     : num    $ sum.voice_offnet_rev_dec.    : num    $ sum.sms_onnet_rev_dec.       : num    $ sum.sms_offnet_rev_dec.      : int    $ sum.recharge_dec.            : int    $ status_dec                   : factor w/ 5 levels   $ type_dec_2                   : factor w/ 6 levels  

i want group 2 of factor variables let's value_seg & region, sum number , create new coulm each factor variable count of observations. tryied aggregate, ddply , others varians type of errors :( in advance

i recommend separate numeric , factor variable , summarize using dplyr. like

library(dplyr)  data %>% select(value_seg,region,sum..... numeric variables) %>%     group_by(value_seg,region) %>% summarize_each(funs(sum)) -> summary1  ## factors  data %>% select(value_seg,region,sum..... factors variables) %>%     group_by(value_seg,region) %>% summarize_each(funs(n)) -> summary2  ## can merge these results  summary <- merge(summary1,summary2,by="value_seg") 

for more details on using package visit link


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -