Create Categories Based On Integer & Numeric Range in R (2 Examples) | Convert Data to Factor Class

preview_player
Показать описание
R code of this video:

num1 <- c(1, 4, 3, 7, 1, 4, 3, 3, 7) # Create numeric example data
num1 # Print numeric example data

class(num1) # Class of data

cat1 # Print categorical data

class(cat1) # Class of data

num2 <- rnorm(100) # Create numeric example data
head(num2) # Head of numeric example data

cat2 <- numeric() # Create empty data object
cat2[num2 < - 1] <- 1 # Assign categories based on numeric range
cat2[num2 >= - 1 & num2 < 0] <- 2
cat2[num2 >= 0 & num2 < 1] <- 3
cat2[num2 >= 1] <- 4
head(cat2) # Head of categorical data

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Thank you so much, your account help me so much to do my assignment. I cannot comment on each video I watched due to time restrictions but seriously... you are a god sent for student who is not majoring in computer science related course

starlight
Автор

Bro I have two dataset both having same ID but one dataset have more ID than other I need common ID of those two dataset can you please teach me.

sabarikrishna
Автор

Great work Sir. I have a question. I have quarterly numerical score data. I am trying to group this data by letter grades such as A, B, C, D, E, F. Each letter grade will represent a range of value. From example 850+ is A, 740-850, 700-740 is B and so forth until F. Could you give some insight into how to do it. The purpose is to conduct a score migration analysis. Thank you

donniemelosso