Hey, I recently came across an assignment where they asked to do one way ANOVA o
ID: 3067485 • Letter: H
Question
Hey, I recently came across an assignment where they asked to do one way ANOVA on a data set in R Studio. The professor gave an example:
##Import data
##Machine Operator Example
MachineOperator <- read.csv(file.choose())
##Check the structure of dataset after you import the data
##You will see the independent variable is recognized as integer
str(MachineOperator)
##In order to change the independent variable to a factor, we use the function called "factor"
MachineOperator$Indep_Operator <- factor(MachineOperator$Indep_Operator)
##Use aov for ANOVA
Operator <-aov(MachineOperator$Dep_opening ~ MachineOperator$Indep_Operator)
##Look at the Operator results by calling its name
##If you want to see SSC, SSE and degree of freedom
Operator
##Summary of the ANOVA, whether to reject or fail to reject the null hypothesis
summary(Operator)
However when I tried factoring, it did not work. How do you use this code:
MachineOperator$Indep_Operator <- factor(MachineOperator$Indep_Operator)
on this different dataset? I am trying to factor the cities for aov. Thanks!!
Machine Operator csv file used by professor: https://drive.google.com/open?id=1iQ-fSMW9J5xgJLFUJwsVlIOEgcMegcpZ
HW CSV FILE: https://drive.google.com/open?id=1Mwpuiupdb5CGq_Dgk5SaXtw2uDSxQkbR
Explanation / Answer
Factoring can be done for various reasons, it can be done to assign labels to categorical data, so that anova and other regression tests can pick it up better.
If the error is coming because it wants the variable as factor , then try this code snipped
df$variable_name <- as.factor(df$variable_name)
here df stands for the data set in question , variable name is the name of variable in the column
so this should work
MachineOperator$Indep_Operator <- as.factor(MachineOperator$Indep_Operator)