Learn R Programming

dedupewider (version 0.1.1)

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

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.

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.

Examples

Run this code
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")

Run the code above in your browser using DataLab