Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. library(dplyr)
  2. library(hflights)
  3.  
  4.  
  5. # Call both head() and summary() on hflights
  6. head(hflights)
  7. summary(hflights)
  8.  
  9. # Convert the hflights data.frame into a hflights tbl
  10. hflights <- tbl_df(hflights)
  11.  
  12. # Display the hflights tbl
  13. hflights
  14.  
  15. # Create the object carriers, containing only the UniqueCarrier variable of hflights
  16. carriers <- hflights$UniqueCarrier
  17.  
  18. # Use lut to translate the UniqueCarrier column of hflights and before doing so
  19. # glimpse hflights to see the UniqueCarrier variablle
  20. glimpse(hflights)
  21.  
  22. lut <- c("AA" = "American", "AS" = "Alaska", "B6" = "JetBlue", "CO" = "Continental",
  23. "DL" = "Delta", "OO" = "SkyWest", "UA" = "United", "US" = "US_Airways",
  24. "WN" = "Southwest", "EV" = "Atlantic_Southeast", "F9" = "Frontier",
  25. "FL" = "AirTran", "MQ" = "American_Eagle", "XE" = "ExpressJet", "YV" = "Mesa")
  26. hflights$UniqueCarrier <- lut[hflights$UniqueCarrier]
  27. # Now glimpse hflights to see the change in the UniqueCarrier variable
  28. glimpse(hflights)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement