to.numeric | R Documentation |
Loops through columsn in dataframe and coerces them to type "numeric"
.
to.numeric(df, id = NULL)
df |
a matrix or dataframe. |
id |
a vector specifying the columns (by name or index) to be converted. The default will convert all columns. |
Coercion consists of as.numeric(as.character(x))
.
A dataframe
Jason Grafmiller
as.numeric
, is.numeric
, to.factor
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.