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

Week1 Cheat Sheet Dplyr Functions

This document is a cheat sheet for dplyr functions in R, detailing commands such as select(), filter(), and write_csv(), along with their syntax and examples. It also includes information on installing and loading packages, reading CSV files, and using the pipe operator. The document is authored by Amrutha Rao and includes a changelog for updates.

Uploaded by

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

Week1 Cheat Sheet Dplyr Functions

This document is a cheat sheet for dplyr functions in R, detailing commands such as select(), filter(), and write_csv(), along with their syntax and examples. It also includes information on installing and loading packages, reading CSV files, and using the pipe operator. The document is authored by Amrutha Rao and includes a changelog for updates.

Uploaded by

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

Cheat Sheet : dplyr functions

Command Syntax Description Example


select() function
select select() selects variables by select(sub_airline,c(month,dayofweek,reporting_airline,crsdepTime))
their names.
filter() function
screens out sub_airline %>% filter(Month == 1) %>% group_by(Reporting_Airline)
filter filter()
observations based on %>% summarize(avg_carrier_delay = mean(CarrierDelay, na.rm = TRUE))
values.
%>% pipe operator To
combine functions, sub_airline <- airlines %>% filter(Origin == "LAX", Dest == "JFK",
Cancelled != 1, Diverted != 1) %>% select(Month, DayOfWeek,
%>% pipe %>%
use the pipe operator. FlightDate, Reporting_Airline, Origin, Dest, CRSDepTime,
operator You can read the pipe CRSArrTime, DepTime, ArrTime, ArrDelay, ArrDelayMinutes,
operator as “then” in CarrierDelay, WeatherDelay)
the function.
install.packages is
used to install the
install package install.packages("packagename") install.pakages("tidyverse")
packages from the R
library.
library() Load the
load package library(packagename) package from R library(tidyverse)
library.
read_csv() reads the
read_csv read_csv(file) csv file using readr read_csv('airline_2m.csv')
package.
download.file() to
download the file
locally using the
download.file()
function.
download.file(url, destfile,
url naming the URL of download.file(url, destfile = "airline_2m.tar.gz")
download.file() method, quiet = FALSE, mode =
"w",cacheOK = TRUE,headers = a resource to be
NULL, …) downloaded.

destfile a character
string with the name
where the downloaded
file is saved.
head(x) function
returns the first part of head(sub_airline)
head() head(x)
a vector, matrix, table,
data frame or function.
tail(x) function
returns the last parts
tail() tail(x) of a vector, matrix, tail(sub_airline)
table, data frame or
function.
write_csv() write.csv(x, file, traitsAsDir write_csv() save write_csv(sub_airline, "lax_to_jfk.csv")
= FALSE, csv2 = TRUE, row.names summaries of
= FALSE, ...)
partitioned breeding
values to CSV files on
disk for further
analyses of processing
with other software or
just for saving
(backing up) results.

x object returned from


function.

file file name with or


without .csv
extension, e.g.file.csv
are valid.

traitsAsDir should
results be saved within
trait folders; the
construction is
file.path(dirname(file),
trait, basename(file));
folders are created if
they do not exist.

csv2 export using


write.csv2 or
write.csv.
glimpse() function
shows you the number
of rows and columns
in the dataset, and
each columnss name,
glimpse() glimpse(tbl, width = type, and data glimpse(sub_airline)
getOption("width")) preview.

tbl A data table

width defaults to the


width of the console.

Author(s)
Amrutha Rao

Changelog
Date Version Changed by Change Description
2023-05-11 1.1 Eric Hao & Vladislav Boyko Updated Page Frames
2021-08-05 1.0 Amrutha Rao Initial Version

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