On May 29, 2012, at 11:01 AM, RBB wrote:

HI!!!

I have a table containing qualitative and quantitative data; one of the columns contains "Level of education", and the possibilities are "none", "High school", "college"; I want to give the value 0 to "none", the value 1
to "High school", and 2 to "college", but I got the following error:

In `[<-.factor`(`*tmp*`, educa = "college", value = 2) :
 invalid factor level, NAs generated


WHAT IS WRONG????? :S :S :S


Hard to say. Although we can be fairly sure you have a factor and that your do NOT have an R contingency table. If you really had a table it would be one thing. A dataframe is another thing and one that is much more common.

dfrm <- data.frame(lev=factor(c("none", "high", "low", "high", "low")))
> dfrm
   lev
1 none
2 high
3  low
4 high
5  low

> levels(dfrm$lev)<- 2:0
> dfrm
  lev
1   0
2   2
3   1
4   2
5   1

Notice that a factor variable's levels are ordered alphabetically, so "high" < "low" < "none" and if you wnat the numbers to match up you need to mentally figure out the right order to make the matching work properly.

(It would be better practice not to overwrite the levels of an existing factor, since that action makes it very easy to really hash up the data.
--
David.

THANKS A LOT!!!!!!!!!!!!!!

--
View this message in context: 
http://r.789695.n4.nabble.com/PROBLEMS-with-In-factor-tmp-ORDERED-FACTOR-tp4631736.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to