Trying to make magrittr pinping
function more graceful and readable. However, the best I can do about this is as following. How can I improve it? Please find the referential code, and advise. Thanks
DF <- data.frame(a=letters[1:10], b=1L:10L, c=1.01:1.10, d=rep(TRUE,10), e=10L:1L)
cols <- lapply(DF,class) %>% unlist()
cols[which(cols %in% c("integer","numeric"))]
# b c e
#"integer" "numeric" "integer"
#
# yet, I'd still like to get rid of the variables.
the best I can do in piping is like this. Tried with %$%
, but failed.
(lapply(DF,class) %>% unlist)[
which(lapply(DF,class) %>% unlist() =="integer" |
lapply(DF,class) %>% unlist() =="numeric")]
can I make it something like this?
lapply(DF,class) %>% unlist %$% .[which(. %in% c("integer","numeric"))]
# of course, it doesn't work