Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calcPercentile() refinements #408

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

calcPercentile() refinements #408

wants to merge 3 commits into from

Conversation

jack-davison
Copy link
Collaborator

This PR is a revision of calcPercentile().

New Features

  • Added the type argument, consistent with timeAverage().

  • Added the prefix argument, which allows users to define a different column name than percentile.XX.

  • Added start.date and end.date, passed to timeAverage().

  • The function will now error if a pollutant is not a column in mydata.

Bug Fixes

  • There was this argument, start which wasn't doing anything. I assume it was meant to go to timeAverage(), so I've done that and renamed it to date.start.

Documentation

  • Markdown roxygen2.

  • Inherit param definitions from timeAverage().

  • Added NEWS.md item.

Examples

devtools::load_all()
#> ℹ Loading openair

calcPercentile(mydata)
#> # A tibble: 90 × 2
#>    date                percentile.50
#>    <dttm>                      <dbl>
#>  1 1998-01-01 00:00:00             2
#>  2 1998-02-01 00:00:00             2
#>  3 1998-03-01 00:00:00             4
#>  4 1998-04-01 00:00:00             7
#>  5 1998-05-01 00:00:00             7
#>  6 1998-06-01 00:00:00             4
#>  7 1998-07-01 00:00:00            NA
#>  8 1998-08-01 00:00:00             4
#>  9 1998-09-01 00:00:00             4
#> 10 1998-10-01 00:00:00             4
#> # ℹ 80 more rows

calcPercentile(mydata, percentile = c(10, 50, 90), prefix = "p")
#> # A tibble: 90 × 4
#>    date                  p10   p50   p90
#>    <dttm>              <dbl> <dbl> <dbl>
#>  1 1998-01-01 00:00:00     0     2  12  
#>  2 1998-02-01 00:00:00     0     2   5  
#>  3 1998-03-01 00:00:00     1     4  12  
#>  4 1998-04-01 00:00:00     3     7  18  
#>  5 1998-05-01 00:00:00     2     7  20  
#>  6 1998-06-01 00:00:00     2     4  11.1
#>  7 1998-07-01 00:00:00    NA    NA  NA  
#>  8 1998-08-01 00:00:00     2     4  13  
#>  9 1998-09-01 00:00:00     1     4  12  
#> 10 1998-10-01 00:00:00     1     4  12.2
#> # ℹ 80 more rows

calcPercentile(mydata, pollutant = "noz")
#> Error in `calcPercentile()`:
#> ✖ pollutant 'noz' not present in data.
#> ℹ Columns in mydata: date, ws, wd, nox, no2, o3, pm10, so2, co, and pm25

calcPercentile(mydata, type = "wd")
#> Warning: 219 missing wind direction line(s) removed
#> # A tibble: 720 × 3
#>    date                wd    percentile.50
#>    <dttm>              <ord>         <dbl>
#>  1 1998-01-01 00:00:00 N               2  
#>  2 1998-02-01 00:00:00 N               1  
#>  3 1998-03-01 00:00:00 N               6  
#>  4 1998-04-01 00:00:00 N              14  
#>  5 1998-05-01 00:00:00 N              10  
#>  6 1998-06-01 00:00:00 N               5  
#>  7 1998-07-01 00:00:00 N              NA  
#>  8 1998-08-01 00:00:00 N               7.5
#>  9 1998-09-01 00:00:00 N               2  
#> 10 1998-10-01 00:00:00 N               4  
#> # ℹ 710 more rows

Created on 2025-02-01 with reprex v2.1.1

- add `type` and `surffix` args

- fix args passed to `timeAverage()`

- roxygen2md & styler

- error if pollutant not present

- use purrrr

- inherit params from `timeAverage()`
data.thresh = 0, start = NA) {

make.percentile <- function(mydata, pollutant = "o3", avg.time = "month", percentile = 50,
data.thresh = 0, start = NA) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's this 'start' argument, that seemingly never gets used.

@jack-davison jack-davison mentioned this pull request Feb 1, 2025
11 tasks
@jack-davison jack-davison added bug Bugs in the current release of openair enhancement Ideas for new features for openair utilities 🛠 Openair data utilities, e.g., timeAverage labels Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs in the current release of openair enhancement Ideas for new features for openair utilities 🛠 Openair data utilities, e.g., timeAverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant