| 1. |
How Will You Convert A Factor Variable To Numeric In R Language ? |
|
Answer» A factor variable can be converted to numeric using the as.numeric() function in R language. However, the variable FIRST needs to be converted to CHARACTER before being converted to numberic because the as.numeric() function in R does not return original values but RETURNS the vector of the levels of the factor variable. X <- factor(c(4, 5, 6, 6, 4)) X1 = as.numeric(as.character(X)) A factor variable can be converted to numeric using the as.numeric() function in R language. However, the variable first needs to be converted to character before being converted to numberic because the as.numeric() function in R does not return original values but returns the vector of the levels of the factor variable. X <- factor(c(4, 5, 6, 6, 4)) X1 = as.numeric(as.character(X)) |
|