OneBite.Dev - Coding blog in a bite size

convert variable from string to float in R

Code snippet on how to convert variable from string to float in R

  x <- as.numeric(as.character(x))

This code will convert the variable x from a string to a float in R. To break it down, the command ‘as.numeric’ will convert the data type into numeric values. The ‘as.character’ command is then wrapped around the variable, which will convert the variable into a character string. Last, the converted character string is assigned back to the original variable, thus completing the conversion from string to float.

r