Check out example codes for "r - transform as factor". It will help you in understanding the concepts better.

Code Example 1

df$myvar <- as.numeric(as.character(df$myvar))
df$myvar <- as.factor(df$myvar)

Learn ReactJs, React Native from akashmittal.com