ft_combine | R Documentation |
Combines two vectors, which may be of unequal lengths, into a factor vector and sorts based on the levels of either the first or second vector.
ft_combine(vector1, vector2, sort_by = 1, decreasing = FALSE)
vector1 |
The first vector to combine. |
vector2 |
The second vector to combine. |
sort_by |
An integer (1 or 2) indicating which vector's levels to use for sorting. Default is |
decreasing |
Logical. Should the sorting be in decreasing order? Default is |
A factor vector combining both vectors and sorted based on specified levels.
# Example vectors of unequal lengths
vector1 <- c('apple', 'banana', 'cherry')
vector2 <- c('date', 'fig', 'grape', 'honeydew')
# Combine and sort based on vector1 levels
combined_factor1 <- ft_combine(vector1, vector2, sort_by = 1)
print(combined_factor1)
# Combine and sort based on vector2 levels
combined_factor2 <- ft_combine(vector1, vector2, sort_by = 2)
print(combined_factor2)
# Combine with decreasing order based on vector1
combined_factor3 <- ft_combine(vector1, vector2, sort_by = 1, decreasing = TRUE)
print(combined_factor3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.