# 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
if (FALSE) {
# 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)
}
Run the code above in your browser using DataLab