Skip to content

Instantly share code, notes, and snippets.

@ramnov
Last active November 17, 2016 20:00
Show Gist options
  • Save ramnov/e0be973e4087a9f1dd92abf7d36a37f6 to your computer and use it in GitHub Desktop.
Save ramnov/e0be973e4087a9f1dd92abf7d36a37f6 to your computer and use it in GitHub Desktop.
Create rollup/aggregate variables in the same dataset
install.packages("devtools")
install.packages("dplyr")
library("devtools")
library("dplyr")
install_github("RevolutionAnalytics/dplyrXdf")
airline_demo_xdf_file <- file.path(rxGetOption("sampleDataDir"), "AirlineDemoSmall.xdf")
airline <- RxXdfData(airline_demo_xdf_file)
smry <- airline %>% group_by(DayOfWeek) %>%
summarise(DayOfWeekMeans=mean(CRSDepTime),
DayOfWeekStdDev=sd(CRSDepTime),
DayOfWeekMin=min(CRSDepTime),
DayOfWeekMax=max(CRSDepTime),
DayOfWeekN=n())
airline_demo_with_summary <- left_join(airline, smry, by="DayOfWeek")
head(airline_demo_with_summary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment