% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/categorical_to_numeric.R
\name{cat_to_num}
\alias{cat_to_num}
\alias{cat_to_num2}
\title{Convert Categorical Values to Numeric Improvement to seq_along()}
\usage{
cat_to_num(x, decreasing = FALSE)

cat_to_num2(x, decreasing = FALSE)
}
\arguments{
\item{x}{A vector containing categorical values (character or factor)}

\item{decreasing}{logical. Should the sort be increasing or decreasing?}
}
\value{
A numeric vector where each category is mapped to a number based on its
sorted position. NA values in the input remain NA in the output.
}
\description{
Converts categorical values into numeric by sorting unique values
alphabetically/numerically and assigning sequential numbers starting from 1
}
\examples{
# Example 1: Basic character vector
fruits <- c("apple", "banana", "apple", "cherry", "banana")
cat_to_num(fruits, decreasing = FALSE)  # Returns: 1, 2, 1, 3, 2

# Example 2: Vector with NAs
grades <- c("A", NA, "C", "B", "A", NA)
cat_to_num(grades)  # Returns: 1, NA, 3, 2, 1, NA

# Example 3: Factor input
animals <- factor(c("dog", "cat", "bird", "cat", "dog"))
cat_to_num(animals)  # Returns: 3, 2, 1, 2, 3

# Example 4: Numeric categories
sizes <- c("XL", "S", "M", "XS", "L")
cat_to_num(sizes)  # Returns: 5, 2, 3, 1, 4

# Example 5: Single category
status <- c("active", "active", "active")
cat_to_num(status)  # Returns: 1, 1, 1

# Examples for cat_to_num2

# Assign numeric values to a set of categorical values
# Call the value assignment to assign
# a numeric value to a new categorical value

cat_to_num2(letters[1:7])("b")
cat_to_num2(letters[1:7], decreasing = FALSE)("d")
# the above assigns numeric values to letters a-g
# and then calls the number for "a"

cat_vals_5 <- c("apple","orange","guava")
num_equiv <- cat_to_num2(cat_vals_5)

applenum = num_equiv("apple")


}
