Re: [R] initialize a factor vector

From: Patrick Burns <pburns_at_pburns.seanet.com>
Date: Sat, 19 Jul 2008 17:44:40 +0100

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 'call' factor on the result of the call
> to 'c'.
>
>
> Patrick Burns
> patrick_at_burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
> Johannes Huesing wrote:
>> 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:
>>
>> The output type is determined from the highest type of the
>> components in the hierarchy NULL < raw < logical < integer < real
>> < complex < character < list < expression.
>> As factor is a class (of the whole vector) and not a type (of a
>> single element), c does not seem to preserve the object information,
>> i.e. there
>> does not seem to be a c.factor, correct?
>>
>>
>
> ______________________________________________
> 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.
>
>



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. Received on Sat 19 Jul 2008 - 16:46:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 19 Jul 2008 - 17:32:00 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive