I would like to combine .table pipelining with magrittr pipelining. I can go from data.table to%>%, but I can't figure out how to get back to the [] [] pipeline of the data.table style.
Here is an example:
> tbl = data.table(grp=c(1,1,1,2,2,2,3,3,3,4,4), y=rnorm(11)) > tbl grp y 1: 1 0.08150 2: 1 1.51330 3: 1 -0.26154 4: 2 -0.12746 5: 2 0.10747 6: 2 0.16502 7: 3 0.54139 8: 3 -0.04194 9: 3 0.02373 10: 4 2.00756 11: 4 1.05523 > tbl[, .(.N, mean(y)), by=grp][order(-N)] %>% head(n=3) %>% .[, N := NULL] grp V2 1: 1 0.44442 2: 2 0.04834 3: 3 0.17439 > tbl[, .(.N, mean(y)), by=grp][order(-N)] %>% head(n=3) %>% .[, N := NULL][, plot(grp, V2)] Error in `[.data.table`(., .[, `:=`(N, NULL)], , plot(grp, V2)) : 'by' or 'keyby' is supplied but not j Calls: %>% ... freduce -> withVisible -> <Anonymous> -> [ -> [.data.table >
How to return to [] [] after%>%?
I know that this particular example can be completely rewritten with [] and without%>%, but I am not interested in this every time. I would like to be able to write [] []%>% [] [] patterns.
r data.table magrittr
Clayton stanley
source share