Hi all.

I think it would be nice to be able to combine levels of a factor on
creation a la

 x <- rep(0:5,5)

 y <- factor(x,levels=0:5,labels=c('1','1',2:5))  ## (1)

 y
 [1] 1 1 2 3 4 5 1 1 2 3 4 5 1 1 2 3 4 5 1 1 2 3 4 5 1 1 2 3 4 5
Levels: 1 1 2 3 4 5

I thougt this would (should?) create a factor with 5 levels, ie
combining 0 and 1 in x into one level in y.

I find it hard to predict the behavior of the following lines:

 table(factor(y))          ## Odd ?
 1  1  2  3  4  5 
10  0  5  5  5  5 
 table(factor(factor(y)))  ## This is what I want
 1  2  3  4  5 
10  5  5  5  5 

It also seems strange that this should be the way to go:
 levels(y) <- levels(y)   ## Does what I want following (1) even tough
it appear to be a void statement?
 y
y
 [1] 1 1 2 3 4 5 1 1 2 3 4 5 1 1 2 3 4 5 1 1 2 3 4 5 1 1 2 3 4 5
Levels: 1 2 3 4 5

Am I missing an important point about factors or the factor function?

steen

Steen Ladelund, statistician
+4543233275 [EMAIL PROTECTED]
Research Center for Prevention and Health
Glostrup University Hospital, Denmark
www.fcfs.kbhamt.dk

______________________________________________
R-help@stat.math.ethz.ch 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