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 data across which function will be performed. If NULL, first column in data will be used. By default all columns will be used.

direction

A character vector of length 1 indicating where to move NA. Can be one of "top", "right", "bottom", "left". If NULL and also by default, "right" direction will be used.

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")

[Package dedupewider version 0.1.0 Index]