Publications by Joey Campbell

functions52_demo

15.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. Read the source code for each of the following three functions, puzzle out what they do, and then brainstorm better names. f1 <- function(string, prefix) { substr(string, 1, nchar(prefix)) == prefix } f2 <- function(x) { ...

5656 sym R (448 sym/13 pcs)

functions51_demo

15.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("lubridate")) 1.Why is TRUE not a parameter to rescale01()? What would happen if x contained a single missing value, and na.rm was FALSE? The code for rescale01() is reproduced below. rescale01...

14340 sym R (3132 sym/39 pcs)

creating_dts48_demo

15.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("lubridate")) 1. What happens if you parse a string that contains invalid dates? ret <- ymd(c("2010-10-10", "bananas")) 1 failed to parse. print(class(ret)) [1] "Date" ret [1] "2010-10-10" NA ...

1716 sym R (530 sym/20 pcs)

timespan50_demo

15.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("lubridate")) 1. Why is there months() but no dmonths()? There is no direct unambiguous value of months in seconds since months have differing numbers of days. 31 days: January, March, May, Ju...

6322 sym R (1035 sym/18 pcs)

dtcomponents49_demo

15.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("lubridate")) suppressPackageStartupMessages(library("nycflights13")) package 㤼㸱nycflights13㤼㸲 was built under R version 3.6.3 The following code from the chapter is used make_datetime_...

11312 sym R (3217 sym/17 pcs) 9 img

fact_order_mod47_demo

14.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. There are some suspiciously high numbers in tvhours. Is the mean a good summary? summary(gss_cat[["tvhours"]]) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 0.000 1.000 2.000 2.981 4.000 24.000 10146 gss...

5669 sym R (2674 sym/22 pcs) 4 img

gss46_demo

14.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. Explore the distribution of rincome (reported income). What makes the default bar chart hard to understand? How could you improve the plot? My first attempt is to use geom_bar() with the default settings. rincome_plot <- gss_c...

7821 sym R (2470 sym/14 pcs) 7 img

stringi45_demo

14.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 suppressPackageStartupMessages(library("stringi")) 1 Find the stringi functions that: 1. Count the number of words. 2. Find duplicated strings. 3. Generate random text. The answer to each part follows. 1. To count the number of word...

5044 sym R (1715 sym/25 pcs)

otherPatterns44_demo

14.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. How would you find all strings containing \ with regex() vs. with fixed()? str_subset(c("a\\b", "ab"), "\\\\") [1] "a\\b" str_subset(c("a\\b", "ab"), fixed("\\")) [1] "a\\b" 2. What are the five most common words in sentences? ...

1353 sym R (355 sym/7 pcs)

splitting43_demo

14.03.2020

suppressPackageStartupMessages(library("tidyverse")) package 㤼㸱tidyverse㤼㸲 was built under R version 3.6.3 1. Split up a string like “apples, pears, and bananas” into individual components. x <- c("apples, pears, and bananas") str_split(x, ", +(and +)?")[[1]] [1] "apples" "pears" "bananas" Exercise 2. Why is it better to split u...

3106 sym R (616 sym/11 pcs)