as_numeric2: As.numeric but also works for factors

View source: R/utility_funs.R

as_numeric2R Documentation

As.numeric but also works for factors

Description

Wrapper for as.numeric that works the same as as.numeric for everything except factors for which it returns the levels of the factor (if it can), rather than the underlying integers

Usage

as_numeric2(x)

Arguments

x

vector to convert to double.

Details

Should work fine as the only (base) methods for as.numeric are difftime and POSIXlt which don't also have factor as class. Could be problematic if some class inherits factor, but then provides their own as.numeric method, which this function would override. could of course get function to check for this and to avoid, but think it is very unlikely.


WhiteJP/jpw documentation built on April 17, 2025, 5:47 a.m.