I am attempting to develop a multiple regression model using selected model variables that should all be treated as numeric (mostly real) values. However, R considers one specific variable "mass" automatically to be of class "factor", probably because "mass" consists of integer values that are repeated. I now want to force R to treat "mass" as a numeric variable in the regression but am not sure how to do this.> class(mass) <- "numeric"does not help me. Could anyone advise me on this? Kind regards, Robin Smit -------------------------------------------- TNO Science & Technology Business Unit Automotive Environmental Studies & Testing PO Box 6033, 2600 JA Delft THE NETHERLANDS ph. +31 (0)15 269 7464 fax +31 (0)15 269 6874 robin.smit@tno.nl http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/milieu studies/environmental_studies_and/ <http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/milie ustudies/environmental_studies_and/> -------------------------------------------- This e-mail and its contents are subject to the DISCLAIMER at http://www.tno.nl/disclaimer/email.html [[alternative HTML version deleted]]
Smit, R. (Robin) (IenT) wrote:> I am attempting to develop a multiple regression model using selected > model variables that should all be treated as numeric (mostly real) > values. > However, R considers one specific variable "mass" automatically to be of > class "factor", probably because "mass" consists of integer values that > are repeated. > I now want to force R to treat "mass" as a numeric variable in the > regression but am not sure how to do this. > > >>class(mass) <- "numeric" > > > does not help me. > > Could anyone advise me on this?It is in the FAQ 7.10 How do I convert factors to numeric? http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f HTH Gav -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
as.numeric() On Fri, 6 May 2005, Smit, R. (Robin) (IenT) wrote:> I am attempting to develop a multiple regression model using selected > model variables that should all be treated as numeric (mostly real) > values. > However, R considers one specific variable "mass" automatically to be of > class "factor", probably because "mass" consists of integer values that > are repeated. > I now want to force R to treat "mass" as a numeric variable in the > regression but am not sure how to do this. > > > class(mass) <- "numeric" > > does not help me. > > Could anyone advise me on this? > > Kind regards, > Robin Smit > > > -------------------------------------------- > TNO Science & Technology > > Business Unit Automotive > Environmental Studies & Testing > PO Box 6033, 2600 JA Delft > THE NETHERLANDS > > ph. +31 (0)15 269 7464 > fax +31 (0)15 269 6874 > robin.smit at tno.nl > http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/milieu > studies/environmental_studies_and/ > <http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/milie > ustudies/environmental_studies_and/> > > -------------------------------------------- > > > > > > This e-mail and its contents are subject to the DISCLAIMER at http://www.tno.nl/disclaimer/email.html > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >Paulo Justiniano Ribeiro Jr LEG (Laborat??rio de Estat??stica e Geoinforma????o) Departamento de Estat??stica Universidade Federal do Paran?? Caixa Postal 19.081 CEP 81.531-990 Curitiba, PR - Brasil Tel: (+55) 41 361 3573 Fax: (+55) 41 361 3141 e-mail: paulojus at est.ufpr.br http://www.est.ufpr.br/~paulojus
On Fri, 6 May 2005, Paulo Justiniano Ribeiro Jr wrote:> as.numeric()No, please see FAQ 7.10.> On Fri, 6 May 2005, Smit, R. (Robin) (IenT) wrote: > >> I am attempting to develop a multiple regression model using selected >> model variables that should all be treated as numeric (mostly real) >> values. >> However, R considers one specific variable "mass" automatically to be of >> class "factor", probably because "mass" consists of integer values that >> are repeated.Rather, you made it of class factor: R just follows instructions.>> I now want to force R to treat "mass" as a numeric variable in the >> regression but am not sure how to do this. >> >>> class(mass) <- "numeric" >> >> does not help me. >> >> Could anyone advise me on this? >> >> Kind regards, >> Robin Smit >> >> >> -------------------------------------------- >> TNO Science & Technology >> >> Business Unit Automotive >> Environmental Studies & Testing >> PO Box 6033, 2600 JA Delft >> THE NETHERLANDS >> >> ph. +31 (0)15 269 7464 >> fax +31 (0)15 269 6874 >> robin.smit at tno.nl >> http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/milieu >> studies/environmental_studies_and/ >> <http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/milie >> ustudies/environmental_studies_and/> >> >> -------------------------------------------- >> >> >> >> >> >> This e-mail and its contents are subject to the DISCLAIMER at http://www.tno.nl/disclaimer/email.html >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >> >> > > Paulo Justiniano Ribeiro Jr > LEG (Laborat?rio de Estat?stica e Geoinforma??o) > Departamento de Estat?stica > Universidade Federal do Paran? > Caixa Postal 19.081 > CEP 81.531-990 > Curitiba, PR - Brasil > Tel: (+55) 41 361 3573 > Fax: (+55) 41 361 3141 > e-mail: paulojus at est.ufpr.br > http://www.est.ufpr.br/~paulojus > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- 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
Hi On 6 May 2005 at 8:51, Paulo Justiniano Ribeiro Jr wrote:> as.numeric()Not exactly correct. as.numeric(as.character()) gives you what you probably want ,if "mass" is really factor ;) see str(mass) Cheers Petr> > > > On Fri, 6 May 2005, Smit, R. (Robin) (IenT) wrote: > > > I am attempting to develop a multiple regression model using > > selected model variables that should all be treated as numeric > > (mostly real) values. However, R considers one specific variable > > "mass" automatically to be of class "factor", probably because > > "mass" consists of integer values that are repeated. I now want to > > force R to treat "mass" as a numeric variable in the regression but > > am not sure how to do this. > > > > > class(mass) <- "numeric" > > > > does not help me. > > > > Could anyone advise me on this? > > > > Kind regards, > > Robin Smit > > > > > > -------------------------------------------- > > TNO Science & Technology > > > > Business Unit Automotive > > Environmental Studies & Testing > > PO Box 6033, 2600 JA Delft > > THE NETHERLANDS > > > > ph. +31 (0)15 269 7464 > > fax +31 (0)15 269 6874 > > robin.smit at tno.nl > > http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/mi > > lieu studies/environmental_studies_and/ > > <http://www.tno.nl/industrie_en_techniek/mobiliteit_en_(transport)/m > > ilie ustudies/environmental_studies_and/> > > > > -------------------------------------------- > > > > > > > > > > > > This e-mail and its contents are subject to the DISCLAIMER at > > http://www.tno.nl/disclaimer/email.html [[alternative HTML version > > deleted]] > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > Paulo Justiniano Ribeiro Jr > LEG (Laborat??rio de Estat??stica e Geoinforma????o) > Departamento de Estat??stica > Universidade Federal do Paran?? > Caixa Postal 19.081 > CEP 81.531-990 > Curitiba, PR - Brasil > Tel: (+55) 41 361 3573 > Fax: (+55) 41 361 3141 > e-mail: paulojus at est.ufpr.br > http://www.est.ufpr.br/~paulojus > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz