Re: [R] Factor to numeric

From: Don MacQueen <macq_at_llnl.gov>
Date: Thu, 24 Apr 2008 09:21:42 -0700

If you have a variable that is supposed to be numeric, but R thinks it is a factor, then you may (probably) have something in your input that is not a number. You changed the commas to decimal points at Prof. Ripley's suggestion. You still have the same error message. Therefore, you probably still have something in your input that is not a number.

try:

   unique(ekob$PAP)
and see what you get

Assuming you created this dataframe using read.table() (or read.delim(), etc.), I'd suggest you read the documentation for that function very carefully, and inspect your input data for non-numeric strings where there should be a numeric string.

It would be helpful if you show what you tried, and the error message, from *after* you changed to decimal points.

-Don

At 5:31 PM +0200 4/24/08, Jojje Andersson wrote:
>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:
>>ripley_at_stats.ox.ac.uk> To: dietaamigo_at_hotmail.com> CC:
>>r-help_at_r-project.org> Subject: Re: [R] Factor to numeric> > 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 don't get it right as R
>>take the variables for factors.> >> >> >> ekobsub1 <- subset(ekob,
>>PAP>0,25 & PAP<0,6 & CAP>0,1 & CAP<0,6 & FAP>0,1)> > Error in
>>`[.data.frame`(x, r, vars, drop = drop) : object "CAP" not found> >
>>In addition: Warning message:> > In Ops.factor(PAP, 0) : > not
>>meaningful for factors> >> >>
>>ekobn<-as.numeric(as.character(ekob[["PAP"]]))> > Warning
>>message:> > NAs introduced by coercion> >> >> > Thanks!> >> >
>>/Jojje> >> >
>>_________________________________________________________________> >
>>[[elide!
> d Hotmail spam]]> >> > px?sc_cmp2=JS_INT_SEMSN_NLPCV> >
>[[alternative HTML version deleted]]> >> >
>______________________________________________> >
>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.> >> >
>-- > Brian D. Ripley, ripley_at_stats.ox.ac.uk> Professor of Applied
>Statistics, http://www.stats.ox.ac.uk/~ripley/> University of
>Oxford, Tel: +44 1865 272861 (self)> 1 South Parks Road, +44 1865
>272866 (PA)> Oxford OX1 3TG, UK Fax: +44 1865 272595
>_________________________________________________________________
>[[elided Hotmail spam]]
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>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.

-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

______________________________________________
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 Thu 24 Apr 2008 - 17:33:57 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 Thu 24 Apr 2008 - 18:30:31 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