10.5 Add Counts

20200814 Using dplyr::add_count() a new column will be added to the dataset recording the size of groups. The column name will be n.

ds %<>%
  add_count(location) %T>%
  {
    select(., date, location, n) %>%
    sample_frac() %>%
    print()
  }
## # A tibble: 275,410 × 3
##    date       location          n
##    <date>     <chr>         <int>
##  1 2015-04-17 SydneyAirport  5751
##  2 2014-07-07 Launceston     5782
##  3 2024-09-27 NorfolkIsland  5751
##  4 2018-01-07 Nhil           4320
##  5 2023-07-29 NorahHead      5746
##  6 2011-01-15 AliceSprings   5782
##  7 2013-12-08 Witchcliffe    5625
##  8 2011-06-04 Newcastle      4030
##  9 2025-06-06 Cairns         5782
## 10 2017-06-02 Albany         5781
## # ℹ 275,400 more rows
names(ds)
##  [1] "date"            "location"        "min_temp"        "max_temp"       
##  [5] "rainfall"        "evaporation"     "sunshine"        "wind_gust_dir"  
##  [9] "wind_gust_speed" "wind_dir_9am"    "wind_dir_3pm"    "wind_speed_9am" 
## [13] "wind_speed_3pm"  "humidity_9am"    "humidity_3pm"    "pressure_9am"   
## [17] "pressure_3pm"    "cloud_9am"       "cloud_3pm"       "temp_9am"       
## [21] "temp_3pm"        "rain_today"      "risk_mm"         "rain_tomorrow"  
## [25] "n"


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