How to use dplyr chaining to access "internal" variables

New to (d) plyr, working through a chain, the main question — for example, hflights — is to use one of these built-in vars to create the main plot:

hflights %>% group_by(Year, Month, DayofMonth) %>% select(Year:DayofMonth, ArrDelay, DepDelay) %>% summarise( arr = mean(ArrDelay, na.rm = TRUE), dep = mean(DepDelay, na.rm = TRUE) ) %>% plot (Month, arr) 

Error in match.fun (panel): object 'arr' not found

I can do this work step by step, but can I get where I want to go somehow with%>% ...

+2
source share
1 answer

plot() does not work. The closest you can get is:

 library(dplyr) library(hflights) summary <- hflights %>% group_by(Year, Month, DayofMonth) %>% select(Year:DayofMonth, ArrDelay, DepDelay) %>% summarise( arr = mean(ArrDelay, na.rm = TRUE), dep = mean(DepDelay, na.rm = TRUE) ) summary %>% plot(arr ~ Month, .) 

Another option is to use ggvis, which is clearly designed to work with pipes:

 library(ggvis) summary %>% ggvis(~Month, ~arr) 
+3
source

Source: https://habr.com/ru/post/978220/


All Articles