Learn R Programming

ksformat (version 0.3.5)

finput: Create Invalue Format (Reverse Formatting like 'SAS' INVALUE)

Description

Creates an invalue format that converts formatted labels back to values. This is similar to 'SAS' PROC FORMAT with INVALUE statement. The invalue is automatically stored in the global format library if name is provided.

Usage

finput(..., name = NULL, target_type = "numeric", missing_value = NA)

Value

An object of class "ks_invalue" containing the invalue definition. The object is also stored in the format library if name is given.

Arguments

...

Named arguments defining label-value mappings (reverse of fnew). Example: "Male" = 1, "Female" = 2.

name

Character. Optional name for the invalue format. If provided, the invalue is automatically registered in the global format library.

target_type

Character. Type to convert to: "numeric" (default), "integer", "character", or "logical". INVALUE formats produce numeric output by default; character-to-character conversion should use a regular VALUE format (fnew) instead.

missing_value

Value to use for missing inputs (default: NA)

Examples

Run this code
# Convert text labels to numeric codes
finput(
  "Male" = 1,
  "Female" = 2,
  name = "sex_inv"
)

# Apply using finputn (numeric invalue by name)
finputn(c("Male", "Female", "Unknown"), "sex_inv")
# [1]  1  2 NA
fclear()

Run the code above in your browser using DataLab