Hello all, First of all, thanks for your examples to calculate the mode value. But now my problem is the next: I have a?factor and I'm trying to convert it to number with as.numeric(x) but when I see the number it's different, I mean if I have: b<-1,042 d<-as.numeric(b) then when I show d, it appears 432 and I want to work with 1,042 because then I want to calculate the median of three values Thanks so much Carlos
If it is a factor, you have to convert to character first and then numeric: d <- as.numeric(as.character(b)) On Mon, Sep 15, 2008 at 1:26 PM, Carlos Morales <carlosmoralesdiego at yahoo.es> wrote:> Hello all, > > First of all, thanks for your examples to calculate the mode value. But now my problem is the next: > > I have a factor and I'm trying to convert it to number with as.numeric(x) but when I see the number it's different, I mean if I have: > > b<-1,042 > d<-as.numeric(b) > > then when I show d, it appears 432 and I want to work with 1,042 because then I want to calculate the median of three values > > > Thanks so much > Carlos > > > > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
I think your problem is the comma. Why are you using it? b <- 1042> str(b)num 1042 Cheers, Alex On Mon, 2008-09-15 at 17:26 +0000, Carlos Morales wrote:> Hello all, > > First of all, thanks for your examples to calculate the mode value. But now my problem is the next: > > I have a factor and I'm trying to convert it to number with as.numeric(x) but when I see the number it's different, I mean if I have: > > b<-1,042 > d<-as.numeric(b) > > then when I show d, it appears 432 and I want to work with 1,042 because then I want to calculate the median of three values > > > Thanks so much > Carlos > > > > > ______________________________________________ > 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.-- Alexandre Swarowsky Soils and Biogeochemistry Graduate Group University of California at Davis One Shields Avenue Davis CA 95618 Office: (530)752-4131 cell: (530)574-3028
Try this: d <- as.numeric(gsub(",", ".", as.character(b))) On Mon, Sep 15, 2008 at 2:26 PM, Carlos Morales <carlosmoralesdiego@yahoo.es> wrote:> Hello all, > > First of all, thanks for your examples to calculate the mode value. But now > my problem is the next: > > I have a factor and I'm trying to convert it to number with as.numeric(x) > but when I see the number it's different, I mean if I have: > > b<-1,042 > d<-as.numeric(b) > > then when I show d, it appears 432 and I want to work with 1,042 because > then I want to calculate the median of three values > > > Thanks so much > Carlos > > > > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]