merge_right_or_left: An internal function to that tells collapse whether to...

Description Usage Arguments Value Note See Also Examples

View source: R/collapse.R

Description

An internal function to that tells collapse whether to collapse with the category to the left or to the right, depending on which adjacent category is smaller, or based on user preference in case of a tie.

Usage

1
merge_right_or_left(v, i, prefer = c("left", "right"))

Arguments

v

A vector of response categories.

i

An index based on a table of sorted (ascending) response categories of v. i must range from 1 to the maximum number of response categories. For example, for response categories 1, 2, 3, 4, and 5, i can be 1, 2, 3, 4, or 5.

prefer

A user supplies preference of whether to merge left or right in the case of a tie (i.e., equal response counts at i - 1 and i + 1.

Value

"left" or "right"; this tells collapse which direction to merge to.

Note

This is intended as an internal function to the collapse() function. Use with care for other purposes.

See Also

collapse()

merge_w_left()

merge_w_right()

Examples

1
2
3
4
5
6
7
8
## Not run: 

sparse_vector <- c(1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 5)
merge_right_or_left(sparse_vector, 2, "left")
merge_right_or_left(sparse_vector, 2, "right")


## End(Not run)

jameswgriffith/jamie documentation built on Dec. 20, 2021, 9:03 p.m.