如何使用dplyr中的链接访问“内部”变量 [英] How to use chaining in dplyr to access "internal" variables

查看:154
本文介绍了如何使用dplyr中的链接访问“内部”变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



新的(d)plyr,通过链接工作,一个基本问题 - 对于hflights示例,要使用这些嵌入的var之一来制作一个基本的情节: pre> hflights%>%
group_by(Year,Month,DayofMonth)%>%
select(Year:DayofMonth,ArrDelay,DepDelay)%>%
summaryize(
arr = mean(ArrDelay,na.rm = TRUE),
dep = mean(DepDelay,na.rm = TRUE)
)%>%
plot(Month,arr)

match.fun(面板)中的错误:对象'arr'not found



我可以让这项工作逐步进行,但是我可以通过%>%

解决方案

plot()不能这样工作。最接近的是:

 库(dplyr)
库(hflights)

摘要< - hflights%>%
group_by(Year,Month,DayofMonth)%>%
select(Year:DayofMonth,ArrDelay,DepDelay)%>%
summaryize
arr = mean(ArrDelay,na.rm = TRUE),
dep = mean(DepDelay,na.rm = TRUE)


summary%> %
plot(arr〜Month,。)

另一个选择是使用ggvis,明确地设计为使用管道:

  library(ggvis)
summary%>%
ggvis (〜月,〜arr)


New to (d)plyr, working through chaining, a basic question - for the hflights example, want to use one of these embedded vars to make a basic 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 make this work going step by step, but can I get where I want to go somehow with %>%...

解决方案

plot() doesn't work that way. The closest you could 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 alternative is to use ggvis, which is explicitly designed to work with pipes:

library(ggvis)
summary %>%
  ggvis(~Month, ~arr)

这篇关于如何使用dplyr中的链接访问“内部”变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆