cc: Enhanced control for combining values

Description Usage Arguments Details Examples

View source: R/cc.R

Description

Enhanced control for combining values

Usage

1
cc(..., recursive = FALSE)

Arguments

...

objects to be concatenated.

recursive

logical. If recursive = TRUE, the function recursively descends through lists (and pairlists) combining all their elements into a vector.

Details

This function returns the same as base c, but if all elements of ... are of class factor or ordered, it returns the lowest common denominator, i.e. an object of class ordered or factor. Ordering of the levels (also for unordered factors) is only preserved if it is identical accross all element in .... Otherwise, it is determined by cfactor, which is called internarlly. Refer to the section 'Details' in the cfactor documentation for further details.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
char1 <- as.factor(sample(letters, 5))
char2 <- as.factor(sample(letters, 5))
cc(char1, char2) # probably more reasonable than
c(char1, char2) 
## Not run: 
## warnings
# no warning since levels identical
a_to_d <- cfactor(letters[1:2], levels = letters[1:5])
b_to_d <- cfactor(letters[1:5])
cc(a_to_d, b_to_d)

# warning for differing order of levels
a_to_d <- cfactor(letters[1:2], levels = letters[1:5])
d_to_a <- cfactor(letters[1:2], levels = rev(letters[1:5]))
cc(a_to_d, d_to_a)

# warning for different levels
some_levels <- cfactor(letters[1:2], levels = letters[1:5])
all_levels <- cfactor(letters[1:2], levels = letters)
cc(all_levels, some_levels, some_levels)

## End(Not run)

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