append: Vector Merging

Description Usage Arguments Details Value Examples

View source: R/append.R

Description

Vector Merging

Usage

1
append(x, values, after = length(x))

Arguments

x

the vector to be modified.

values

to be included in the modified vector.

after

a subscript, after which the values are to be appended.

Details

A refined version of append that allows for factor appending.

Value

If x and values are of class factor, the function returns an object of class factor whereas levels are determined using cfactor internally. Levels are only preserved if both elements have the same levels. In addition, ordering is only preserved if the order is also identical. Otherwise, the base method is called directly.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
f <- factor(c('c','a','a',NA,'b','a'), levels= c('a','b','c'))
g <- factor(sample(letters[4:10]), levels = sample(letters[4:10]))
base::append(f, g) # not nice
refactor::append(f, g) # probably what you want

# ordered factors
f_ord <- factor(f, ordered = TRUE)
g_ord <- factor(g, ordered = TRUE)
append(f_ord, g_ord) 
append(f_ord, f_ord) 

jonmcalder/refactor documentation built on Nov. 16, 2020, 3:46 a.m.