R中的重组函数有问题
我正在尝试构建一个函数,用于查找数据集中的特定列,以便从我整理的航班延误数据集中更轻松地生成条形图 我已经编写了构建grouper函数的代码。它没有出错,所以我为我想要生成的绘图编写了代码。当我运行它时,它声称它找不到函数“Regroups”R中的重组函数有问题,r,function,ggplot2,dplyr,R,Function,Ggplot2,Dplyr,我正在尝试构建一个函数,用于查找数据集中的特定列,以便从我整理的航班延误数据集中更轻松地生成条形图 我已经编写了构建grouper函数的代码。它没有出错,所以我为我想要生成的绘图编写了代码。当我运行它时,它声称它找不到函数“Regroups” GrouperFunc <- function(df, ...) df %>% regroup(list(...)) AirPlot <- function(departure, arrival, groupon){ # De
GrouperFunc <- function(df, ...) df %>% regroup(list(...))
AirPlot <- function(departure, arrival, groupon){
# Departure and arrival can be cities that are being entered.
departCode <- AirportCode(departure)
arriveCode <- AirportCode(arrival) # Call our earlier AirportCode function to get the airport ID
tempDB <- subset(flights, ORIGIN_AIRPORT_ID == departCode & DEST_AIRPORT_ID == arriveCode) # Only get flights for our
grouped <- GrouperFunc(tempDB, groupon) # flight path
# Use our GrouperFunc to have dplyr group our data into categories
summaryDF <- summarize(grouped, mean = mean(ARR_DELAY)) # Call summarize from our grouped data frame
# Now that the data is in a good format, create the ggplot bar chart
finalBarPlot <- ggplot(summaryDF, aes_string(x=groupon, y='mean')) +
geom_bar(color="black", width = 0.2, stat = 'identity') +
guides(fill=FALSE)+
xlab(groupon) +
ylab('Average Delay (minutes)')+
ggtitle((paste('Flights from', departure, 'to', arrival)))
return(finalBarPlot)
}
AirPlot('Dallas', 'Chicago', 'UNIQUE_CARRIER')
# Hide Traceback
# Rerun with Debug
# Error in regroup(., list(...)) : could not find function "regroup"
GrouperFunc%重新分组(列表(…)
AirPlot正如@r2evans告诉我的,在新的dplyr版本中,Regroups是不推荐的。现在我们改用groupby。因此,代码应该是这样的:
GrouperFunc%groupby.(…)
换句话说,
重新分组(列表(…)变成分组依据(…)您似乎正在使用非基本包。除了ggplot2
,您还使用了哪些软件包?除了ggplot2和dplyr之外没有其他软件包。请原谅我的怀疑:错误:找不到对象“AirportCode”
,与AirPlot
相同。但是,您似乎正在使用(或试图使用)旧版本的dplyr
:在0.7.0(参考:)中删除了重组
功能。哦,开枪。。。你说得对。回到绘图板上的时间到了……(对不起,AirPlot
错误是我在咖啡因作用下犯的。)groupby\uuu
与其他*\uu
动词一样,也不赞成使用tidyeval