How to convert a data frame variable to numeric in the R programming language. More details: https://statisticsglobe.com/convert-d...
R code:
data <- data.frame(x1 = c(1, 5, 8, 2), # Create example data frame
x2 = c(3, 2, 5, 2),
x3 = c(2, 7, 1, 2))
data$x1 <- as.factor(data$x1) # First column is a factor
data$x2 <- as.character(data$x2) # Second column is a character
data$x3 <- as.integer(data$x3) # Third column is an integer
sapply(data, class) # Get classes of all columns
data$x1 <- as.numeric(as.character(data$x1)) # Convert one variable to numeric
sapply(data, class) # Get classes of all columns
Watch video Convert Data Frame Column to Numeric in R | Example: Change Factor & Character Variable | as.numeric online without registration, duration hours minute second in high quality. This video was added by user Statistics Globe 06 January 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 73,476 once and liked it 568 people.