The as.numeric() function in R is used to convert a character vector into a numeric vector.
as.numeric(x)
The as.numeric() function takes a single and mandatory parameter value, x, which represents the character vector to be converted.
The as.numeric() function returns a numeric vector object.
# creating a character vectorx = c('1', '2', '3', '4', '5')# implementing the as.numeric() functiony = as.numeric(x)# printing the numeric vectory# checking if its a numeric matrixis.numeric(y)
x that contains the character vector.as.numeric() function on the x variable. The result is assigned to another variable y.y.is.numeric() function to check if the variable y is numeric or not.