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

2013-04-01 Thread Peter Ehlers
On 2013-04-01 13:08, Matthew Lundberg wrote: Note the edited subject line! I don't know why I typed it as it was before. This says that as.numeric(as.character(f)) will work regardless of the implementation, and I agree. It's the recommendation to use as.numeric(levels(f))[f] that has me wonde

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

2013-04-01 Thread Matthew Lundberg
Note the edited subject line! I don't know why I typed it as it was before. This says that as.numeric(as.character(f)) will work regardless of the implementation, and I agree. It's the recommendation to use as.numeric(levels(f))[f] that has me wondering about section 2.3.1 of the language defini

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 wrote: > > When used as an index, the factor is impl

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, A

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 as.numeric(as.chara

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 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 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
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 - secti

Re: [R] Factor to Numeric

2010-05-26 Thread David Winsemius
On May 26, 2010, at 4:05 AM, Ivan Calandra wrote: What about (not tested because no sample data, and I'm definitely unsure of my lapply() solution): lapply(data[2:13], FUN=as.character) lapply(data[2:13], FUN=as.numeric) ? That would not preserve any of the output since no assignments were

Re: [R] Factor to Numeric

2010-05-26 Thread Ivan Calandra
What about (not tested because no sample data, and I'm definitely unsure of my lapply() solution): lapply(data[2:13], FUN=as.character) lapply(data[2:13], FUN=as.numeric) ? data[2:13] should correspond to the 12 Month columns. There might be a way to combine both lines but I don't think lapply w

Re: [R] Factor to Numeric

2010-05-26 Thread Mohan L
On Wed, May 26, 2010 at 1:13 PM, Ivan Calandra wrote: > Hi, > > What about: > as.numeric(as.character(data$State)) > ? > What I what is, I want to convert all the column excluding State to factor to numeric in the data frame. So that I will send this data frame to another function to total .

Re: [R] Factor to Numeric

2010-05-26 Thread Ivan Calandra
Hi, What about: as.numeric(as.character(data$State)) ? Ivan Le 5/26/2010 09:32, Mohan L a écrit : Dear All, I have a data frame with State and 12 Months as column. I want to convert all the 12 month column from factor to numeric. any help will be greatly appreciated. str(data) 'da

[R] Factor to Numeric

2010-05-26 Thread Mohan L
Dear All, I have a data frame with State and 12 Months as column. I want to convert all the 12 month column from factor to numeric. any help will be greatly appreciated. > str(data) 'data.frame':33 obs. of 9 variables: $ State: Factor w/ 33 levels "Andaman and Nicobar Islands",..: 1 2 3

Re: [R] Factor to numeric

2008-04-24 Thread Don MacQueen
t; to "." in both datafile and code but the problem >remains identical. >Cheers! >Jojje > > > > >> Date: Thu, 24 Apr 2008 09:16:38 +0100> From: >>[EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: >>r-help@r-project.org> Subject: Re: [R] Fa

Re: [R] Factor to numeric

2008-04-24 Thread Jorge Ivan Velez
t; > Date: Thu, 24 Apr 2008 09:16:38 +0100> From: [EMAIL PROTECTED]> To: > [EMAIL PROTECTED]> CC: r-help@r-project.org> Subject: Re: [R] Factor > to numeric> > The decimal point in R is always '.', never ','.> > On Thu, 24 > Apr 2008, Jojje A

Re: [R] Factor to numeric

2008-04-24 Thread Prof Brian Ripley
s such. Cheers! Jojje   __ > Date: Thu, 24 Apr 2008 09:16:38 +0100 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > CC: r-help@r-project.org > Subject: Re: [R] Factor to numeric > > The decimal point in R is always '.', never ','. > > O

Re: [R] Factor to numeric

2008-04-24 Thread Jojje Andersson
Hello! Thanks! I changed the "," to "." in both datafile and code but the problem remains identical. Cheers! Jojje > Date: Thu, 24 Apr 2008 09:16:38 +0100> From: [EMAIL PROTECTED]> To: [EMAIL > PROTECTED]> CC: r-help@r-project.org> Subject: Re: [

Re: [R] Factor to numeric

2008-04-24 Thread Prof Brian Ripley
The decimal point in R is always '.', never ','. On Thu, 24 Apr 2008, Jojje Andersson wrote: > > Hello! > I have a problem whith a data.frame. I want to make a subset where some of > the variables have values within ceartain limits. > The variables are proportions like 1,00, 0,54, 0,00 etc. > I

[R] Factor to numeric

2008-04-24 Thread Jojje Andersson
Hello! I have a problem whith a data.frame. I want to make a subset where some of the variables have values within ceartain limits. The variables are proportions like 1,00, 0,54, 0,00 etc. I don't get it right as R take the variables for factors. > ekobsub1 <- subset(ekob, PAP>0,25 & PAP<0,6