10.12 Modify Columns

ds %>%
  select(date, location, pressure_9am)
## # A tibble: 191,431 x 3
##    date       location pressure_9am
##    <date>     <chr>           <dbl>
##  1 2008-12-01 Albury          1008.
##  2 2008-12-02 Albury          1011.
##  3 2008-12-03 Albury          1008.
##  4 2008-12-04 Albury          1018.
##  5 2008-12-05 Albury          1011.
##  6 2008-12-06 Albury          1009.
##  7 2008-12-07 Albury          1010.
##  8 2008-12-08 Albury          1013.
##  9 2008-12-09 Albury          1009.
## 10 2008-12-10 Albury          1007 
## # … with 191,421 more rows
ds %>%
  mutate(pressure_9am=round(pressure_9am, 0)) %>%
  select(date, location, pressure_9am)
## # A tibble: 191,431 x 3
##    date       location pressure_9am
##    <date>     <chr>           <dbl>
##  1 2008-12-01 Albury           1008
##  2 2008-12-02 Albury           1011
##  3 2008-12-03 Albury           1008
##  4 2008-12-04 Albury           1018
##  5 2008-12-05 Albury           1011
##  6 2008-12-06 Albury           1009
##  7 2008-12-07 Albury           1010
##  8 2008-12-08 Albury           1013
##  9 2008-12-09 Albury           1009
## 10 2008-12-10 Albury           1007
## # … with 191,421 more rows

To convert all character columns to be numeric:

ds %>%
  mutate(across(where(is.character), as.numeric))


Your donation will support ongoing development and give you access to the PDF version of the book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.