This code reads in a CSV file, converts the Salary column to a factor, and creates new variables based on the original 'League', 'NewLeague', and 'Division' variables. It then converts the 'Division' and 'League' variables to factors and prints a summary of the data.

h1 <- read.csv('C:\Users\24537\Documents\WeChat Files\wxid_ixkphacpw6dr22\FileStorage\File\2023-04\1(1).csv')
head(h1)
h1$Salary <- factor(h1$Salary)
is.factor(h1$Salary)
h1$League <- ifelse(h1$League == 'A', 0, 1)
h1$NewLeague <- ifelse(h1$NewLeague == 'A', 0, 1)
h1$Division <- ifelse(h1$Division == 'E', 0, 1)
head(h1)
h1$Division <- factor(h1$Division)
h1$League <- factor(h1$League)
h1$NewLeague <- factor(h1$NewLeague)
summary(h1)
Data Preprocessing in R: Converting Variables and Summarizing Data

原文地址: https://www.cveoy.top/t/topic/n2sa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录