From ab58324caa826e30faa9c58de389edc913db165c Mon Sep 17 00:00:00 2001 From: avahoffman Date: Thu, 13 Jun 2024 09:34:53 -0400 Subject: [PATCH] minor changes! --- modules/Data_Classes/Data_Classes.Rmd | 24 +++++++++++-------- .../Data_Classes/lab/Data_Classes_Lab_Key.Rmd | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/Data_Classes/Data_Classes.Rmd b/modules/Data_Classes/Data_Classes.Rmd index 6101881a3..98d1f999f 100644 --- a/modules/Data_Classes/Data_Classes.Rmd +++ b/modules/Data_Classes/Data_Classes.Rmd @@ -231,11 +231,12 @@ head(circ) ## Class conversion in with a dataset -Say we want to change `daily` to be an integer. We would need to use mutate to help us modify that column or create a new column. Let's create a new one so it is easier to see what is happening. +Say we want to change `daily` to be an integer. We would need to use `mutate()`. Let's create a new column 'daily_int' so it is easier to see what is happening. ```{r} -circ_updated <- mutate(circ, daily_int= as.integer(daily)) -circ_updated %>% select(daily, daily_int) +circ %>% + mutate(daily_int= as.integer(daily)) %>% + select(daily, daily_int) ``` @@ -375,18 +376,21 @@ There are functions in case your data have only date, hour and minute (`ymd_hm() ## In a dataframe Note dates are always displayed year month day, even if made with `mdy`! + ```{r} -circ <- mutate(circ, date_formatted = mdy(date)) %>% - relocate(date_formatted, .before = orangeBoardings) -glimpse(circ) +circ_dates <- circ %>% select(date) +circ_dates <- + circ_dates %>% mutate(date_formatted = mdy(date)) +glimpse(circ_dates) ``` -## Once a variable is a date type we can convert to other types +## Once a variable is a date type we can convert to other types + ```{r} -circ %>% mutate(year = year(date_formatted)) %>% - mutate(month = month(date_formatted)) %>% - relocate(c(year, month), .before = orangeBoardings) %>% +circ_dates %>% + mutate(year = year(date_formatted)) %>% + mutate(month = month(date_formatted)) %>% glimpse() ``` diff --git a/modules/Data_Classes/lab/Data_Classes_Lab_Key.Rmd b/modules/Data_Classes/lab/Data_Classes_Lab_Key.Rmd index ef3fc50db..d1e1c914a 100644 --- a/modules/Data_Classes/lab/Data_Classes_Lab_Key.Rmd +++ b/modules/Data_Classes/lab/Data_Classes_Lab_Key.Rmd @@ -9,7 +9,7 @@ editor_options: ### 1.1 -Load all the libraries we will use in this lab. +Load all the packages we will use in this lab. ```{r} library(readr) @@ -119,7 +119,7 @@ glimpse(circ) ### P.2 -Use `range()` function on `date_formatted` variable to display the range of dates in the data set. How does this compare to that of `date`? Why? (Hint: use the pull function first to pull the values.) +Use `range()` function on `date_formatted` variable to display the range of dates in the data set. How does this compare to that of `date`? Why? (Hint: use the `pull` function first to pull the values.) ```{r P.2response} pull(circ, date_formatted) %>% range()