| umx_as_numeric | R Documentation |
Apply as.numeric to multiple columns of a dataframe.
umx_as_numeric(df, which = NULL, force = FALSE)
df |
A |
which |
which columns to convert (default (null) selects all) |
force |
Whether to force conversion to numeric for non-numeric columns (defaults to FALSE) |
data.frame
Other Data Functions:
noNAs(),
prolific_anonymize(),
prolific_check_ID(),
prolific_read_demog(),
prolific_scoring_stub(),
umx,
umxFactor(),
umxGSEM_sim_snps(),
umxHetCor(),
umx_cont_2_quantiles(),
umx_lower2full(),
umx_make_GxE_data(),
umx_make_MR_data(),
umx_make_TwinData(),
umx_make_fake_data(),
umx_make_raw_from_cov(),
umx_merge_randomized_columns(),
umx_polychoric(),
umx_polypairwise(),
umx_polytriowise(),
umx_read_lower(),
umx_rename(),
umx_reorder(),
umx_score_scale(),
umx_select_valid(),
umx_stack(),
umx_strings2numeric()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.