As the data file I imported does not contain the variable names, I set them using the R function names(). This code ran without an issue:
#Add names to the dataset
names(Data) <- c("Gender", "Age", "MonthlyExpenses", "MaritalStatus", "HomeStatus", "Occupation", "BankingInstitution", "YearsEmployed", "NoPriorDefault", "Employed", "CreditScore", "DriversLicense", "AccountType", "MonthlyIncome", "AccountBalance", "Approved")
However, the following code produces an error:
> # Manually define the variables
>
> Data$Gender <- as.factor(Data$Gender)
Error in is.factor(x) : object 'Data' not found
> Data$Age <- as.numeric(Data$Age)
Error: object 'Data' not found
> Data$MonthlyExpenses <- as.integer(Data$MonthlyExpenses)
Error: object 'Data' not found
> Data$MaritalStatus <- as.factor(Data$MaritalStatus)
Error in is.factor(x) : object 'Data' not found
> Data$HomeStatus <- as.factor(Data$HomeStatus)
Error in is.factor(x) : object 'Data' not found
>
Why is the error occurring, given that I created "names(Data)" prior to defining the variables?