Description Usage Arguments Details Value Note See Also Examples
Replace missing values (NA) in a table and lists
1 2 3 4 5 6 7 |
.tbl |
list-like or table-like structure. |
.na |
scalar, vector or function as described in |
... |
additional args; either a unnamed list of columns (quoted or not) or name=function pairs. See Details. |
.vars |
character; names of columns to be imputed |
.predicate |
dply-type predicate functions |
impute is similar to other dplyr verbs especially dplyr::mutate(). Like
dplyr::mutate() it operates on columns. It changes only missing values
(NA) to the value specified by .na.
Behavior:
Behavior depends on the values of .na and ....
impute can be used for three replacement operatations:
impute( .tbl, .na ) : ( missing ... ) Replace missing values
in ALL COLS by .na. This is analogous to impute_all.
impute( .tbl, .na, ... ) : ( ... is an unnamed list) Replace
column(s) specified in ... by .na. Columns are specified as an
unnamed list of quoted or unquoted column names. This is analogous to
impute_at where ... specifies .vars
impute( .tbl. col1=na.*, col2=na.* ) : ( missing .na ) :
Replace by column-specific .na
Additional arguments are to .na are not used; Use impute_at for
this or create your own lambda functions.
impute_all is like impute without specifying .... ... is used
for additional arguments to .na
Returns a object as the same type as .tbl. Columns are mutated to replace
missing values (NA) with value specied by .na and ...
... is used to specify columns in impute but is used as additional
arguments to .na in the other impute_* functions.
The na.tools package.
impute_functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | data(nacars)
## Not run:
nacars %>% impute(0, mpg, cyl)
nacars %>% impute(1:6, mpg, cyl)
nacars %>% impute( na.mean )
nacars %>% impute( mean ) # unsafe
nacars %>% impute( length, mpg, disp )
nacars %>% impute( mean, mpg, disp )
nacars %>% impute( mpg=na.mean, cyl=na.max )
nacars %>% impute( na.mean, c('mpg','disp') )
## End(Not run)
## Not run:
nacars %>% impute_at( -99, .vars=1:3 )
nacars %>% impute_at( .na=na.mean, .vars=1:6 )
# Same, uses `...` for additional args
nacars %>%
impute_at( .na=mean , .vars=1:6, na.rm = TRUE )
nacars %>% impute_at( .na=na.mean, .vars = c('mpg','cyl', 'disp') )
## End(Not run)
## Not run:
nacars %>% impute_all( -99 )
nacars %>% impute_all( na.min )
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.