Re: [R] initialize a factor vector

2008-07-19 Thread Patrick Burns
Somehow the mail system garbled my last sentence. It should read: You want to call 'factor' on the result of the call to 'c'. Pat Patrick Burns wrote: 'c' does not have a method for factors. If you were to try implementing one, you would probably quickly figure out why not. You want to call

Re: [R] initialize a factor vector

2008-07-19 Thread Patrick Burns
'c' does not have a method for factors. If you were to try implementing one, you would probably quickly figure out why not. You want to call 'call' factor on the result of the call to 'c'. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Gu

Re: [R] initialize a factor vector

2008-07-19 Thread Johannes Huesing
I have found that factor vectors are shy beasts. Consider: > empty <- factor(levels=c("eins", "zwei")) > value <- factor("eins", levels=c("eins", "zwei")) > c(empty, value) [1] 1 > empty[1] <- value > empty [1] eins Levels: eins zwei > I could not exactly predict this behaviour, but ?c says:

Re: [R] initialize a factor vector

2008-07-13 Thread Johannes Huesing
Gavin Simpson <[EMAIL PROTECTED]> [Sun, Jul 13, 2008 at 08:18:37PM CEST]: > On Sun, 2008-07-13 at 18:47 +0200, Johannes Huesing wrote: [...] > > as.factor(c("eins", "zwei", "drei"))[FALSE] > > does the job but looks a bit weird. > > [...] > > factor(levels = c("one","two","three")) > factor(0) >

Re: [R] initialize a factor vector

2008-07-13 Thread Gavin Simpson
On Sun, 2008-07-13 at 18:47 +0200, Johannes Huesing wrote: > What is the least surprising way of initializing a factor with > predefined levels and with length 0? > as.factor(c("eins", "zwei", "drei"))[FALSE] > does the job but looks a bit weird. > Notice that one does not need to specify any