filmov
tv
unclass() Function in R (2 Examples) | Convert Factor to Integer | Change Group Names of Factors

Показать описание
R code of this video:
my_fac <- factor(c("A", "B", "A", "A", "C")) # Create example factor
my_fac # Print example factor
my_fac_new1 <- unclass(my_fac) # Convert factor to integer
my_fac_new1 # Print output
class(my_fac_new1) # Check class of updated data
new_names <- c("gr1", "gr2", "gr3") # Specify new group names
new_names # Print new group names
my_fac_new2 <- new_names[unclass(my_fac)] # Change factor levels
my_fac_new2 # Print new data
Follow me on Social Media:
my_fac <- factor(c("A", "B", "A", "A", "C")) # Create example factor
my_fac # Print example factor
my_fac_new1 <- unclass(my_fac) # Convert factor to integer
my_fac_new1 # Print output
class(my_fac_new1) # Check class of updated data
new_names <- c("gr1", "gr2", "gr3") # Specify new group names
new_names # Print new group names
my_fac_new2 <- new_names[unclass(my_fac)] # Change factor levels
my_fac_new2 # Print new data
Follow me on Social Media: