My R code was working perfectly fine in R Studio but when I pasted same code in Kaggle Notebook it started giving errors. It converted my factors to numbers when applied if-