names2 {BBmisc}R Documentation

Replacement for names which always returns a vector.

Description

A simple wrapper for names. Returns a vector even if no names attribute is set. Values NA and "" are treated as missing and replaced with the value provided in missing.val.

Usage

names2(x, missing.val = NA_character_)

Arguments

x

[ANY]
Object, probably named.

missing.val

[ANY]
Value to set for missing names. Default is NA_character_.

Value

[character]: vector of the same length as x.

Examples

x = 1:3
names(x)
## NULL
names2(x)
## [1] NA NA NA
names(x[1:2]) = letters[1:2]
names(x)
## NULL
names2(x)
## [1] NA NA NA

[Package BBmisc version 1.7 Index]