Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

umx_as_numeric

umx_as_numeric


Description

Convert each column of a dataframe to numeric

Usage

umx_as_numeric(df, which = NULL, force = FALSE)

Arguments

df

A [data.frame()] to convert

which

which columns to convert (default (null) selects all)

force

Whether to force conversion to numeric for non-numeric columns (defaults to FALSE)

Value

- data.frame

References

- <https://github.com/tbates/umx>

See Also

Examples

# make mpg into string, and cyl into a factor
df = mtcars
df$mpg = as.character(df$mpg)
df$cyl = factor(df$cyl)
df$am = df$am==1

df = umx_as_numeric(df); str(df) # mpg not touched
df = umx_as_numeric(df, force=TRUE); str(df) # mpg coerced back to numeric
## Not run: 
# coercing a real string will cause NAs
df$mpg = c(letters[1:16]); str(df) # replace mpg with letters.
df = umx_as_numeric(df, force=TRUE); str(df)

## End(Not run)

umx

Structural Equation Modeling and Twin Modeling in R

v4.10.10
GPL-3
Authors
Timothy C. Bates [aut, cre] (<https://orcid.org/0000-0002-1153-9007>), Gillespie Nathan [wit], Michael Zakharin [wit], Brenton Wiernik [ctb], Joshua N. Pritikin [ctb], Michael C. Neale [ctb], Hermine Maes [ctb]
Initial release
2021-11-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.