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

ampute() now preserves the data structure #593

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

gerkovink
Copy link
Member

Fixes #592

library(mice)
boys |> 
  str()
#> 'data.frame':    748 obs. of  9 variables:
#>  $ age: num  0.035 0.038 0.057 0.06 0.062 0.068 0.068 0.071 0.071 0.073 ...
#>  $ hgt: num  50.1 53.5 50 54.5 57.5 55.5 52.5 53 55.1 54.5 ...
#>  $ wgt: num  3.65 3.37 3.14 4.27 5.03 ...
#>  $ bmi: num  14.5 11.8 12.6 14.4 15.2 ...
#>  $ hc : num  33.7 35 35.2 36.7 37.3 37 34.9 35.8 36.8 38 ...
#>  $ gen: Ord.factor w/ 5 levels "G1"<"G2"<"G3"<..: NA NA NA NA NA NA NA NA NA NA ...
#>  $ phb: Ord.factor w/ 6 levels "P1"<"P2"<"P3"<..: NA NA NA NA NA NA NA NA NA NA ...
#>  $ tv : int  NA NA NA NA NA NA NA NA NA NA ...
#>  $ reg: Factor w/ 5 levels "north","east",..: 4 4 4 4 4 4 4 3 3 2 ...

boys |>
  na.omit() |>
  ampute() |>
  (\(x) x$amp)() |>
  str()
#> Warning: Data is made numeric internally, because the calculation of weights
#> requires numeric data
#> 'data.frame':    223 obs. of  9 variables:
#>  $ age: num  8.86 8.87 8.91 9 9 ...
#>  $ hgt: num  125 145 138 136 151 ...
#>  $ wgt: num  31 38.2 30 26.9 48.2 29.4 28 22 35.6 32 ...
#>  $ bmi: num  19.9 18.2 15.8 14.5 21.1 ...
#>  $ hc : num  51.6 54.8 54.7 53.4 50.5 53.9 52.1 54.4 53 52.3 ...
#>  $ gen: Ord.factor w/ 5 levels "G1"<"G2"<"G3"<..: 1 2 1 1 2 1 1 1 2 2 ...
#>  $ phb: Ord.factor w/ 6 levels "P1"<"P2"<"P3"<..: 1 1 1 1 1 1 1 1 1 1 ...
#>  $ tv : int  1 2 2 4 2 2 2 3 2 1 ...
#>  $ reg: Factor w/ 5 levels "north","east",..: 1 4 4 2 3 2 1 3 4 3 ...
#>  - attr(*, "na.action")= 'omit' Named int [1:525] 1 2 3 4 5 6 7 8 9 10 ...
#>   ..- attr(*, "names")= chr [1:525] "3" "4" "18" "23" ...

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

Copy link
Member

@hanneoberman hanneoberman left a comment

Choose a reason for hiding this comment

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

Looks good!

@stefvanbuuren stefvanbuuren merged commit 954e6c6 into amices:master Oct 6, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ampute() should preserve the structure of the original data matrix
3 participants