Learn R Programming

ksformat (version 0.3.5)

ksformat-package: ksformat: 'SAS'-Style 'PROC FORMAT' for R

Description

Provides 'SAS' 'PROC FORMAT'-like functionality for creating and applying value formats in R. The package supports mapping values to labels, range-based formatting, reverse formatting (invalue), and proper handling of missing values (NA, NULL, NaN).

Arguments

Author

Maintainer: Vladimir Larchenko vladimir.larchenko@keystatsolutions.com

Details

Main features:

  • Create value-to-label mappings (formats) with fnew

  • Apply formats to vectors using fput

  • Apply formats by name: fputn (numeric), fputc (character)

  • Reverse formatting with finput, finputn, finputc

  • Apply invalues by name: finputn (numeric), finputc (character)

  • Parse 'SAS'-like format definitions from text with fparse

  • Global format library with auto-registration

  • Range-based formatting for numeric data

Cheat sheet: run ksformat_cheatsheet() to open the HTML version in your browser, or see the files in system.file("doc", package = "ksformat").

Examples

Run this code
fnew("M" = "Male", "F" = "Female", .missing = "Unknown", name = "sex")
fput(c("M", "F", NA), "sex")

fparse(text = '
VALUE age (numeric)
  [0, 18) = "Child"
  [18, 65) = "Adult"
;
')
fputn(c(5, 25), "age")
fclear()

Run the code above in your browser using DataLab