Skip to content

Commit

Permalink
minor changes!
Browse files Browse the repository at this point in the history
  • Loading branch information
avahoffman committed Jun 13, 2024
1 parent 327b5cc commit ab58324
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions modules/Data_Classes/Data_Classes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```


Expand Down Expand Up @@ -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()
```

Expand Down
4 changes: 2 additions & 2 deletions modules/Data_Classes/lab/Data_Classes_Lab_Key.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ab58324

Please sign in to comment.