Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
You didn't show an example of how to recreate your problem, but
this shows up when a term in a model is a factor (or character) variable
with no variation in it. E.g.,
> d <- data.frame(y=1:10, x1=rep(3,10), x2=rep(c("Female","Male"),c(7,3)))
> lm(y ~ x1 + x2, data=d, subset = x2=="Female")
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
You have to look through the dataset to see which column is the offender.
Numeric columns with no variation are accepted; this is just a problem with
character/factor columns:
> lm(y ~ x1 + x2, data=d)
Call:
lm(formula = y ~ x1 + x2, data = d)
Coefficients:
(Intercept) x1 x2Male
4 NA 5
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of sgs sys Sent: Saturday, April 27, 2013 7:59 AM To: r-help at r-project.org Subject: [R] Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : i am getting the following error Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels can any on e suggest how to rectify [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.