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

Impute below dates 158 #331

Merged
merged 2 commits into from
May 1, 2023
Merged

Impute below dates 158 #331

merged 2 commits into from
May 1, 2023

Conversation

njtierney
Copy link
Owner

Description

Implement Date, POSIXct and POSIXlt methods for impute_below()

This works by coercing to numeric, then casting back to the relevant class

Related Issue

Resolves #158

Example

library(naniar)
library(tidyverse)
dat_date <- tibble(
  values = 1:7,
  number = c(111, 112, NA, NA, 108, 150, 160),
  posixct = as.POSIXct(number, origin = "1970-01-01"),
  posixlt = as.POSIXlt(number, origin = "1970-01-01"),
  date = as.Date(number)
  )
dat_date
#> # A tibble: 7 × 5
#>   values number posixct             posixlt             date      
#>    <int>  <dbl> <dttm>              <dttm>              <date>    
#> 1      1    111 1969-12-31 16:01:51 1969-12-31 16:01:51 1970-04-22
#> 2      2    112 1969-12-31 16:01:52 1969-12-31 16:01:52 1970-04-23
#> 3      3     NA NA                  NA                  NA        
#> 4      4     NA NA                  NA                  NA        
#> 5      5    108 1969-12-31 16:01:48 1969-12-31 16:01:48 1970-04-19
#> 6      6    150 1969-12-31 16:02:30 1969-12-31 16:02:30 1970-05-31
#> 7      7    160 1969-12-31 16:02:40 1969-12-31 16:02:40 1970-06-10

date_date_imp <- dat_date %>% 
  mutate(
    number_imp = impute_below(number),
    .after = number
  ) %>% 
  mutate(
    posixct_imp = impute_below(posixct),
    .after = posixct
    ) %>% 
  mutate(
    posixlt_imp = impute_below(posixlt),
    .after = posixlt
  ) %>% 
  mutate(
    date_imp = impute_below(date),
    .after = date
  )
date_date_imp
#> # A tibble: 7 × 9
#>   values number number_imp posixct             posixct_imp        
#>    <int>  <dbl>      <dbl> <dttm>              <dttm>             
#> 1      1    111       111  1969-12-31 16:01:51 1969-12-31 16:01:51
#> 2      2    112       112  1969-12-31 16:01:52 1969-12-31 16:01:52
#> 3      3     NA       103. NA                  1969-12-31 16:01:43
#> 4      4     NA       102. NA                  1969-12-31 16:01:41
#> 5      5    108       108  1969-12-31 16:01:48 1969-12-31 16:01:48
#> 6      6    150       150  1969-12-31 16:02:30 1969-12-31 16:02:30
#> 7      7    160       160  1969-12-31 16:02:40 1969-12-31 16:02:40
#> # ℹ 4 more variables: posixlt <dttm>, posixlt_imp <dttm>, date <date>,
#> #   date_imp <date>

ggplot(dat_date,
       aes(x = values,
           y = date)) + 
  geom_point()
#> Warning: Removed 2 rows containing missing values (`geom_point()`).

ggplot(dat_date,
       aes(x = values,
           y = date)) + 
  geom_miss_point()

Created on 2023-05-01 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.0 (2023-04-21)
#>  os       macOS Ventura 13.2
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Los_Angeles
#>  date     2023-05-01
#>  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.6.1      2023-03-23 [1] CRAN (R 4.3.0)
#>  colorspace    2.1-0      2023-01-23 [1] CRAN (R 4.3.0)
#>  curl          5.0.0      2023-01-12 [1] CRAN (R 4.3.0)
#>  digest        0.6.31     2022-12-11 [1] CRAN (R 4.3.0)
#>  dplyr       * 1.1.2      2023-04-20 [1] CRAN (R 4.3.0)
#>  evaluate      0.20       2023-01-17 [1] CRAN (R 4.3.0)
#>  fansi         1.0.4      2023-01-22 [1] CRAN (R 4.3.0)
#>  farver        2.1.1      2022-07-06 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1      2023-02-24 [1] CRAN (R 4.3.0)
#>  forcats     * 1.0.0      2023-01-29 [1] CRAN (R 4.3.0)
#>  fs            1.6.2      2023-04-25 [1] CRAN (R 4.3.0)
#>  generics      0.1.3      2022-07-05 [1] CRAN (R 4.3.0)
#>  ggplot2     * 3.4.2      2023-04-03 [1] CRAN (R 4.3.0)
#>  glue          1.6.2      2022-02-24 [1] CRAN (R 4.3.0)
#>  gtable        0.3.3      2023-03-21 [1] CRAN (R 4.3.0)
#>  highr         0.10       2022-12-22 [1] CRAN (R 4.3.0)
#>  hms           1.1.3      2023-03-21 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.5      2023-03-23 [1] CRAN (R 4.3.0)
#>  httr          1.4.5      2023-02-24 [1] CRAN (R 4.3.0)
#>  knitr         1.42       2023-01-25 [1] CRAN (R 4.3.0)
#>  labeling      0.4.2      2020-10-20 [1] CRAN (R 4.3.0)
#>  lifecycle     1.0.3      2022-10-07 [1] CRAN (R 4.3.0)
#>  lubridate   * 1.9.2      2023-02-10 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.3.0)
#>  mime          0.12       2021-09-28 [1] CRAN (R 4.3.0)
#>  munsell       0.5.0      2018-06-12 [1] CRAN (R 4.3.0)
#>  naniar      * 1.0.0.9000 2023-05-01 [1] local
#>  pillar        1.9.0      2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.3.0)
#>  purrr       * 1.0.1      2023-01-10 [1] CRAN (R 4.3.0)
#>  R.cache       0.16.0     2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2      2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.25.0     2022-06-12 [1] CRAN (R 4.3.0)
#>  R.utils       2.12.2     2022-11-11 [1] CRAN (R 4.3.0)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.3.0)
#>  readr       * 2.1.4      2023-02-10 [1] CRAN (R 4.3.0)
#>  reprex        2.0.2      2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang         1.1.0      2023-03-14 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.21       2023-03-26 [1] CRAN (R 4.3.0)
#>  rstudioapi    0.14       2022-08-22 [1] CRAN (R 4.3.0)
#>  scales        1.2.1      2022-08-20 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.3.0)
#>  stringi       1.7.12     2023-01-11 [1] CRAN (R 4.3.0)
#>  stringr     * 1.5.0      2022-12-02 [1] CRAN (R 4.3.0)
#>  styler        1.9.1      2023-03-04 [1] CRAN (R 4.3.0)
#>  tibble      * 3.2.1      2023-03-20 [1] CRAN (R 4.3.0)
#>  tidyr       * 1.3.0      2023-01-24 [1] CRAN (R 4.3.0)
#>  tidyselect    1.2.0      2022-10-10 [1] CRAN (R 4.3.0)
#>  tidyverse   * 2.0.0      2023-02-22 [1] CRAN (R 4.3.0)
#>  timechange    0.2.0      2023-01-11 [1] CRAN (R 4.3.0)
#>  tzdb          0.3.0      2022-03-28 [1] CRAN (R 4.3.0)
#>  utf8          1.2.3      2023-01-31 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.2      2023-04-19 [1] CRAN (R 4.3.0)
#>  visdat        0.6.0      2023-02-02 [1] CRAN (R 4.3.0)
#>  withr         2.5.0      2022-03-03 [1] CRAN (R 4.3.0)
#>  xfun          0.39       2023-04-20 [1] CRAN (R 4.3.0)
#>  xml2          1.3.4      2023-04-27 [1] CRAN (R 4.3.0)
#>  yaml          2.3.7      2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Tests

Yes

NEWS + DESCRIPTION

Yes

- Convert to numeric, then impute and convert back to relevant class
- add tests for geom_miss_point() and other dates
- Resolves #158
Merge commit 'f85704bb78f2e8fa84aad84a568ad57ea606445e'

#Conflicts:
#	NEWS.md
@njtierney njtierney merged commit 6008310 into master May 1, 2023
@njtierney njtierney deleted the impute-below-dates-158 branch May 1, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Date method for impute_below
1 participant