to.numeric: Convert columns to numeric

View source: R/to.numeric.R

to.numericR Documentation

Convert columns to numeric

Description

Loops through columsn in dataframe and coerces them to type "numeric".

Usage

to.numeric(df, id = NULL)

Arguments

df

a matrix or dataframe.

id

a vector specifying the columns (by name or index) to be converted. The default will convert all columns.

Details

Coercion consists of as.numeric(as.character(x)).

Value

A dataframe

Author(s)

Jason Grafmiller

See Also

as.numeric, is.numeric, to.factor

Examples

df <- iris
summary(df)

df[2:3] <- lapply(df[2:3], as.factor)
summary(df)

df <- to.numeric(df, 2:3)
# or alternatively
# df <- to.numeric(df, c("Sepal.Width", "Petal.Length"))
summary(df)

jasongraf1/JGmisc documentation built on March 21, 2022, 7:42 a.m.