0% found this document useful (0 votes)
421 views2 pages

Data Handling in R - Introduction To Dplyr

Fresco Play hands on Introduction to dplyr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
421 views2 pages

Data Handling in R - Introduction To Dplyr

Fresco Play hands on Introduction to dplyr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

library(dplyr, warn.

conflicts = FALSE)
dplyrs <- function(){

# print(getwd())
# print(list.files())

# Task 1:
hflights <- read.csv("hflights.csv")
print(dim(hflights))

# Task 2.
# Use the functions head () and tail () to take a look
print(head(hflights))
print(tail(hflights))

# Task 3:
print(head(hflights, 20 ))

# Task 4:
# glimpse () is like a transposed version of print.

glimpse(hflights)

# Task 5:
# Perform the following tasks:

# A. Create a data frame hflights1 which will have first fifty rows of the data
set hflights
d <- hflights[c(1:50),]

# B. Convert hflights1 into a tbl.


hflights1 <- as_tibble(d)

# C. To see how tbl behaves like data frames, save the UniqueCarrier column of
hflights tbl
# as an object named carriers, by using standard R syntax and print it.

carriers <- hflights1$UniqueCarrier


print(carriers)

# Task 6:
# Perform the following tasks:

# A. Create a list abrCarrier which will contain actual carrier names


corresponding to the values in the
# variable UniqueCarrier.

abrCarrier < - c("AA" = "American", "AS" = "Alaska", "B6" = "JetBlue", "CO" =


"Continental", "DL" = "Delta", "OO" = "SkyWest", "UA" = "United", "US" =
"US_Airways", "WN" = "Southwest", "EV" = "Atlantic_Southeast", "F9" = "Frontier",
"FL" = "AirTran", "MQ" = "American_Eagle", "XE" = "ExpressJet", "YV" = "Mesa")

# B. Add a new column Carrier to hflights which will contain the actual Carrier
name by referring abrCarrier and the UniqueCarrier column of hflights.

hflights <- transform( hflights, Carrier= ifelse(hflights$UniqueCarrier %in%


names(abrCarrier), abrCarrier[hflights$UniqueCarrier ], "Error"))
# C. Print the first 10 rows of the data set to view the values in the newly
added column.
print(head(hflights, 10))

dplyrs()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy