[R] Very confused with class

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Aug 21 17:08:17 CEST 2008


This seems to be FAQ Q7.10

On Thu, 21 Aug 2008, Williams, Robin wrote:

> Hi all,
>  I am very confused with class.
>  I am looking at some weather data which I want to use as explanatory
> variables in an lm. R has treated these variables as factors (i.e. with
> different levels), whereas I want them treated as discretely measured
> continuous variables. So I need to reassign the class of these
> variables, right?
> Indeed, doing
> class(southwest$pressure)
> (pressure being air pressure), I get
> #> factor.
>  Now what class should I use to reassign them so that my model fitting
> process goes as I want it to? I have obviously done something wrong. I
> did
> southwest$pressure <- as(southwest$pressure,"numeric")
> numeric seeming like a reasonable class to assign to this variable.
> However, doing some summary stats like
> mean(southwest$pressure)
> #> 341,
> max(southwest$pressure)
> #> 761,
> which is clearly nonsense, as my maximum value is around 1040. Something
> similar has happened to maxtemp (maximum temperature), which I also
> reassigned from a factor to class numeric, which now apparently has a
> maximum value of 147!
>  Clearly it must be the reassignment of class that has caused these
> problems, as summary stats on the data before I reassigned the classes
> were fine. What is wrong with the class numeric? Reading the numeric
> help page didn't reveal anything to me. Can someone suggest the correct
> class?
> Many thanks for any help.
> Robin Williams
> Met Office summer intern - Health Forecasting
> robin.williams at metoffice.gov.uk
>
>
> 	[[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



More information about the R-help mailing list