Added a check to ensure all factors have the same number of levels.
Items (i.e columns) that are not a factor will be converted to a factor using as.factor.
Updated for recent changes.