The as.numeric() function will convert a factor or character value into a numeric value. For instance, if you need to change a factor such as `Gender` into numeric values, the as.numeric() function will assign each group a number and convert it from being coded as a categorical variable to being a quantitative variable. (See factor() for converting quantitative variables into categorical variables).

Example:
# designates `Gender` as a numeric variable and saves it as a new column called `Gen_num`
Fingers$Gen_num <- as.numeric(Fingers$Gender)
# check the data frame
head(select(Fingers, Gender, Gen_num))
Example output:
Related Articles
numeric (in R)
Numeric (in R) is a type of R object that is a quantitative variable.
factor()
The factor() function will convert a quantitative variable into a factor (a categorical variable). This is often needed when categorical variables are dummy coded as numeric values so R treats them as a quantitative variable. For example, when a ...
Variables
A variable is a measurable characteristic or attribute that can take on different values across cases (i.e., observational units such as people, companies, or time points). Types of Variables Variables can be classified by the type of values they ...
Data
Data Data are recorded observations, measurements, or information collected to answer questions, test hypotheses, or make decisions. In statistics and data science, data are the raw material we analyze to discover patterns, relationships, and ...
Vectors
Vectors Vectors are one of the most basic and important data structures in R. A vector is an ordered collection of values of the same data type, such as numbers, characters, or logical (TRUE/FALSE) values. In statistics and data science, vectors are ...