Skip to content

Instantly share code, notes, and snippets.

@sriyoda
Last active February 15, 2016 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sriyoda/01171d8d286a10fa2884 to your computer and use it in GitHub Desktop.
Save sriyoda/01171d8d286a10fa2884 to your computer and use it in GitHub Desktop.
Connections Count
flights <- read.csv("flights (1).csv", stringsAsFactors = F)
airports <- read.csv("airports (1).csv", stringsAsFactors = F)
airports <- filter(airports, iata %in% union(flights$origin, flights$destination)) # subsetting airports by 1-1 matches
orig <- select(count(flights, origin), iata=origin, n1=n) #one-way from count
dest <- select(count(flights, destination), iata=destination, n2=n) #one-way two count
airports <- left_join(airports, select(mutate(left_join(orig, dest),tot=n1+n2),iata, tot)) %>%
filter(!is.na(tot)) # joining origin and destination airports for 1-1 matches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment