gdemin / maditr

Fast Data Aggregation, Modification, and Filtering
61 stars 3 forks source link

Question about na.rm in maditr #12

Closed robertogilsaura closed 4 years ago

robertogilsaura commented 4 years ago

This is not an issue, is a question ..

Can I get the same result in this tables with expss and maditr? Can I modify the use of mean in fun? Column 2016 difference between vox & maspais. I'm looking for equal result in expss and maditr... ` year <- c(2016,2017,2018,2019,2020,2016) psoe <- c(21,32,34,36,36.5,21) pp <- c(15,16,13.5,17,17,15) vox <- c(11,12,11,12,13,NA) cs <- c(1,1,2,4,2,NA) maspais <- c(1,2,3,1,3,5) others <- c(0.3,1,0.4,0.3,0.5, 0.1)

data <- data.frame(year,psoe,pp,vox,cs,maspais,others)

take(data, psoe,pp,vox,cs,maspais,others, fun = mean, by=year) data %>% tab_cols(year) %>% tab_cells(psoe,pp,vox,cs,maspais,others) %>% tab_stat_mean() %>% tab_pivot() %>% t() ` Thanks in advance

gdemin commented 4 years ago

Classic approach is anonymous function:

take(data, psoe,pp,vox,cs,maspais,others, fun = function(x) mean(x, na.rm = TRUE), by=year)

Or, with pipes you can create functions by starting chain with dot: new_fun . %>% my_fun(second_arg = 42). Using this approach:

take(data, psoe,pp,vox,cs,maspais,others, fun = . %>%  mean(na.rm = TRUE), by=year)
robertogilsaura commented 4 years ago

A lot of thanks...

Roberto Gil Saura InvestigaOnline.com | Universitat de València | Universidad Católica de Valencia

Enviado desde mi Samsung J7 2016

El mié., 22 ene. 2020 11:18, Gregory Demin notifications@github.com escribió:

Classic approach is anonymous function:

take(data, psoe,pp,vox,cs,maspais,others, fun = function(x) mean(x, na.rm = TRUE), by=year)

Or, with pipes you can create functions by starting chain with dot: new_fun . %>% my_fun(second_arg = 42). Using this approach:

take(data, psoe,pp,vox,cs,maspais,others, fun = . %>% mean(na.rm = TRUE), by=year)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gdemin/maditr/issues/12?email_source=notifications&email_token=ACWGQPZTLU35TPWIXRQ3QXTQ7AMQNA5CNFSM4KKCTDNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJTAL7Q#issuecomment-577111550, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWGQPZ6UHTKWILSPMX45YTQ7AMQNANCNFSM4KKCTDNA .