na_move {dedupewider} | R Documentation |
Move NA
across columns or rows
Description
For chosen columns, move NA
to right or left (i.e. across columns)
or to top or bottom (i.e. across rows).
Usage
na_move(data, cols = names(data), direction = "right")
Arguments
data |
A data.frame without column named "....idx". |
cols |
A character vector of columns' names in |
direction |
A character vector of length 1 indicating where to move |
Value
A data.frame with only these attributes preserved, which are returned by attributes
function used on object passed to data
parameter.
Type of columns passed to cols
will be coerced to the most general type, although sometimes when
column will contain only NA
, that column will be of type logical.
Note
Internally, function is mainly based on data.table
functions and thus enabling parallel computation
is possible. To do this, just call setDTthreads
before calling na_move
function.
Examples
data <- data.frame(col1 = c(1, 2, 3),
col2 = c(NA, NA, 4),
col3 = c(5, NA, NA),
col4 = c(6, 7, 8))
data
na_move(data, c("col2", "col3", "col4"), direction = "right")