[R] Factor to numeric conversion - as.numeric(as.character(f))[f] - Language definition seems to say to not use this.

2013-04-01 Thread Matthew Lundberg
These two seem to be at odds. Is this the case? From help(factor) - section Warning: To transform a factor f to approximately its original numeric values, as.numeric(levels(f))[f] is recommended and slightly more efficient than as.numeric(as.character(f)). From the language definition -

Re: [R] Factor to numeric conversion - as.numeric(as.character(f))[f] - Language definition seems to say to not use this.

2013-04-01 Thread Ista Zahn
Hi Mathew, In what way are they at odds? On Mon, Apr 1, 2013 at 1:48 PM, Matthew Lundberg matthew.k.lundb...@gmail.com wrote: These two seem to be at odds. Is this the case? From help(factor) - section Warning: To transform a factor f to approximately its original numeric values,

Re: [R] Factor to numeric conversion - as.numeric(as.character(f))[f] - Language definition seems to say to not use this.

2013-04-01 Thread Peter Ehlers
On 2013-04-01 10:48, Matthew Lundberg wrote: These two seem to be at odds. Is this the case? From help(factor) - section Warning: To transform a factor f to approximately its original numeric values, as.numeric(levels(f))[f] is recommended and slightly more efficient than

Re: [R] Factor to numeric conversion - as.numeric(as.character(f))[f] - Language definition seems to say to not use this.

2013-04-01 Thread Matthew Lundberg
When used as an index, the factor is implicitly converted to integer. In the expression as.numeric(levels(f))[f], the vector as.numeric(levels(f)) is indexed by as.integer(f). This appears to rely on the current implementation, as mentioned in section 2.3.1 of the language definition. On Mon,

Re: [R] Factor to numeric conversion - as.numeric(as.character(f))[f] - Language definition seems to say to not use this.

2013-04-01 Thread Bert Gunter
Yup. Note also: as.character.factor function (x, ...) levels(x)[x] But of course this is OK, since this can change if the implementation does. Which is the whole point, of course. -- Bert On Mon, Apr 1, 2013 at 12:16 PM, Matthew Lundberg matthew.k.lundb...@gmail.com wrote: When used as an