
practice.R file)Make sure you have these libraries installed:
Remember: you only need to install packages once!
#> # A tibble: 4 × 5
#> firstName lastName instrument yearOfBirth deceased
#> <chr> <chr> <chr> <dbl> <lgl>
#> 1 John Lennon guitar 1940 TRUE
#> 2 Paul McCartney bass 1942 FALSE
#> 3 Ringo Starr drums 1940 FALSE
#> 4 George Harrison guitar 1943 TRUE
#> # A tibble: 4 × 5
#> firstName lastName instrument yearOfBirth deceased
#> <chr> <chr> <chr> <dbl> <lgl>
#> 1 John Lennon guitar 1940 TRUE
#> 2 Paul McCartney bass 1942 FALSE
#> 3 Ringo Starr drums 1940 FALSE
#> 4 George Harrison guitar 1943 TRUE
Information about John Lennon is in the first row:
#> # A tibble: 1 × 5
#> firstName lastName instrument yearOfBirth deceased
#> <chr> <chr> <chr> <dbl> <lgl>
#> 1 John Lennon guitar 1940 TRUE
beatles data frame in practice.R.csv file)CSV = Comma-Separated Values
practice.RNote the data.csv file in your data folder.
Excel can corrupt your data!
(Don’t believe me? Read this paper)
If you must open it in Excel:
file.path() to make file pathsYour paths start from the folder you opened in Positron
(File › Open Folder… - not double-clicking a file!)
Important: Use read_csv() instead of read.csv()
Use the file.path() and read_csv() functions to load the data.csv file that is in the data folder. Name the data frame object data.
Use the data object to answer the following questions:
stringr + dplyr + readr + ggplot2 + …
Art by Allison Horst
Art by Allison Horst
dplyr “verbs”| “Verb” | What it does |
|---|---|
select() |
Select columns by name |
filter() |
Keep rows that match criteria |
arrange() |
Sort rows based on column(s) |
mutate() |
Create new columns |
summarize() |
Create summary values |
tidyverse concept:%>%%>% as the words “…and then…”select()
select()#> # A tibble: 4 × 5
#> firstName lastName instrument yearOfBirth deceased
#> <chr> <chr> <chr> <dbl> <lgl>
#> 1 John Lennon guitar 1940 TRUE
#> 2 Paul McCartney bass 1942 FALSE
#> 3 Ringo Starr drums 1940 FALSE
#> 4 George Harrison guitar 1943 TRUE
select()Select the columns firstName & lastName
select()Use the - sign to drop columns
select()Select columns based on name criteria:
ends_with() = Select columns that end with a character stringcontains() = Select columns that contain a character stringmatches() = Select columns that match a regular expressionone_of() = Select column names that are from a group of namesselect()Select the columns that end with "Name":
filter()
filter()Keep only the rows with band members born after 1941
filter()Keep only the rows with band members born after 1941
filter()Keep only the rows with band members born after 1941 & are still living
#> # A tibble: 1 × 5
#> firstName lastName instrument yearOfBirth deceased
#> <chr> <chr> <chr> <dbl> <lgl>
#> 1 Paul McCartney bass 1942 FALSE
filter()| Description | Example |
|---|---|
| Values greater than 1 | value > 1 |
| Values greater than or equal to 1 | value >= 1 |
| Values less than 1 | value < 1 |
| Values less than or equal to 1 | value <= 1 |
| Values equal to 1 | value == 1 |
| Values not equal to 1 | value != 1 |
| Values in the set c(1, 4) | value %in% c(1, 4) |
Drop all rows where variable is NA
filter() and select()Get the first & last name of members born after 1941 & are still living
Use the file.path() and read_csv() functions to load the data.csv file that is in the data folder. Name the data frame object data.
Use the data object and the select() and filter() functions to answer the following questions:
dc, that contains only the rows from DC airports.dc_dawn, that contains only the rows from DC airports that occurred at dawn.dc_dawn_birds, that contains only the rows from DC airports that occurred at dawn and only the columns about the species of bird.mutate()
Art by Allison Horst
mutate()Use the yearOfBirth variable to compute the age of each band member
#> # A tibble: 4 × 6
#> firstName lastName instrument yearOfBirth deceased age
#> <chr> <chr> <chr> <dbl> <lgl> <dbl>
#> 1 John Lennon guitar 1940 TRUE 82
#> 2 Paul McCartney bass 1942 FALSE 80
#> 3 Ringo Starr drums 1940 FALSE 82
#> 4 George Harrison guitar 1943 TRUE 79
#> # A tibble: 4 × 7
#> firstName lastName instrument yearOfBirth deceased age meanAge
#> <chr> <chr> <chr> <dbl> <lgl> <dbl> <dbl>
#> 1 John Lennon guitar 1940 TRUE 82 80.8
#> 2 Paul McCartney bass 1942 FALSE 80 80.8
#> 3 Ringo Starr drums 1940 FALSE 82 80.8
#> 4 George Harrison guitar 1943 TRUE 79 80.8
ifelse(<condition>, <if TRUE>, <else>)#> # A tibble: 4 × 6
#> firstName lastName instrument yearOfBirth deceased playsGuitar
#> <chr> <chr> <chr> <dbl> <lgl> <dbl>
#> 1 John Lennon guitar 1940 TRUE 1
#> 2 Paul McCartney bass 1942 FALSE 0
#> 3 Ringo Starr drums 1940 FALSE 0
#> 4 George Harrison guitar 1943 TRUE 1
arrange()Sort beatles data frame by year of birth
arrange()Use the desc() function to sort in descending order
arrange()Compute the band member age, then sort based on the youngest:
#> # A tibble: 4 × 6
#> firstName lastName instrument yearOfBirth deceased age
#> <chr> <chr> <chr> <dbl> <lgl> <dbl>
#> 1 George Harrison guitar 1943 TRUE 79
#> 2 Paul McCartney bass 1942 FALSE 80
#> 3 John Lennon guitar 1940 TRUE 82
#> 4 Ringo Starr drums 1940 FALSE 82
Use the file.path() and read_csv() functions to load the data.csv file that is in the data folder. Name the data frame object data.
Using the data object, create the following new variables:
height_miles: The height variable converted to miles (Hint: there are 5,280 feet in a mile).cost_mil: Is TRUE if the repair costs was greater or equal to $1 million, FALSE otherwise.NA for cost_repairs_infl_adj and re-arrange the resulting data frame based on the highest height and most expensive cost| Item | Description |
|---|---|
| Abstract | Product / technology in just a few sentences |
| Introduction | Description, picture, background |
| Market Opportunity | Identify your customer, competitors, and market size |
| Product Attributes | 2-4 key variables related to product’s design and performance |
| Research Questions | 2-4 research questions you hope to answer about your product |
| Questions | Major outstanding questions to be resolved |
Features your customer cares about
Decisions you are trying to inform
Sign up here for your team proposal 1-on-1 with Prof. Helveston