10.23 Modify Columns

ds %>%
  select(date, location, pressure_9am)
## # A tibble: 275,410 × 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 
## # ℹ 275,400 more rows
ds %>%
  mutate(pressure_9am=round(pressure_9am, 0)) %>%
  select(date, location, pressure_9am)
## # A tibble: 275,410 × 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
## # ℹ 275,400 more rows

To convert all character columns to be numeric:

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


If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0