I am trying to wrap some dplyr magic inside a function to create a data.frame which I then print using xxtable.
The ultimate goal is to have a dplyr version of this , while working and browsing, I come across a very useful summarise_each() function, which after a subset with regroup() (since this is part of the function), I can then use for analysis all columns.
The problem I ran into (so far) is calling is.na() from summarise_each(funs(is.na)) , as I was told Error: expecting a single value .
I do not purposefully place my function only, but a minimal example follows (NB - In this case, group_by() , while in my function I replace it with regroup() ) ...
library(dplyr) library(magrittr) > t <- data.frame(grp = rbinom(10, 1, 0.5), a = as.factor(round(rnorm(10))), b = rnorm(10), c = rnorm(10)) t %>% group_by(grp) %>% ## This is replaced with regroup() in my function summarise_each(funs(is.na)) Error: expecting a single value
This is not done, and calling is.na() is a problem, because if I work out the number of observations in each instead (necessary to get the proportion of absent ones), it works ...
> t %>% group_by(grp) %>%
The real problem is that I don't only need is.na() in each column, but sum(is.na()) according to a related example, so I really would like to ...
> t %>% group_by(grp) %>%
But the problem is that sum(is.na) does not work as I expect (probably because my expectation is wrong!) ...
> t %>% group_by(grp) %>% ## This is replaced with regroup() in my function summarise_each(funs(nmiss = sum(is.na))) Error in sum(.Primitive("is.na")) : invalid 'type' (builtin) of argument
I tried calling is.na() explicitly with parentheses, but this also returns an error ...
> t %>% + group_by(grp) %>%
Any advice or pointers to documentation would be greatly appreciated.
Thanks,
slackline