I'm trying to use the lm package to look at how a continuous variable is influenced by a 2-level factor. I've made sure R sees the factor as a factor (it does), and that it sees 2 levels of the factor (it does). However, when I try to run the model, I get the following error message:
`Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels`
Below is the code I used to read in my data, exclude empty cells and read data as factors. Does anyone have a sense of why I am getting an error message saying that my factor does not have 2 or more levels?
`amfcol <- read.csv(file="amfcol.csv", na.strings = c(" ", ""),header=T)
amfcol <- na.omit(amfcol)
head(amfcol)
str(amfcol)
amfcol <- amfcol[1:141,]
amfcol$amf <- as.factor(amfcol$amf)
is.factor(amfcol$amf)
levels(amfcol$amf)
is.factor(amfcol$fert)
levels(amfcol$fert)
mod1 <- lm(arbcol~amf, data=amfcol)`
Thanks!