fct2num: fct2num()

View source: R/fct2num.R

fct2numR Documentation

fct2num()

Description

Converts a factor to a numeric vector while adjusting for the starting value of the numeric vector. Useful for converting from categorical responses (e.g. "Agree","Disagree") to numeric (1,2).

Usage

fct2num(factor_vector, start = 1, print = "message")

Arguments

factor_vector

A vector that is a factor.

start

Defaults to 1. The starting value of the resultant numeric vector. The value inputted for start will be the lowest numeric value for the lowest factor level.

print

Defaults to "message". Determines if the text messages of this function uses cat() or message(). This affects the behaviour in specific Rmarkdown chunks.

Examples

a <- factor(c("Agree","Disagree","Agree","Agree","Disagree"))
fct2num(a)
fct2num(a, start = 0) # if likert scales begin at 0

Aaron0696/aaRon documentation built on July 27, 2023, 2:05 p.m.