Re: [R] as.numeric looses precision

2015-07-02 Thread PIKAL Petr
not be represented precisely in binary arithmetic. Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bos, Roger Sent: Thursday, July 02, 2015 3:55 PM To: r-help@r-project.org Subject: [R] as.numeric looses precision I have a string

[R] as.numeric looses precision

2015-07-02 Thread Bos, Roger
I have a string that contains a number and when I convert it to a number I loose precision and I would like to know if there is a way to avoid that. Here is my example: p - 1087.003489 as.numeric(p, digits=6) R gives me 1087.003: p - 1087.003489 as.numeric(p, digits=6) [1] 1087.003 I

Re: [R] as.numeric looses precision

2015-07-02 Thread Kehl Dániel
:54 To: r-help@r-project.org Tárgy: [R] as.numeric looses precision I have a string that contains a number and when I convert it to a number I loose precision and I would like to know if there is a way to avoid that. Here is my example: p - 1087.003489 as.numeric(p, digits=6) R gives me

Re: [R] as.numeric looses precision

2015-07-02 Thread Sarah Goslee
Hi Roger, You're mixing up storage and display: p - 1087.003489 p - as.numeric(p) p [1] 1087.003 # the default value for digits = 7, which can be changed with option() print(p, digits=4) [1] 1087 print(p, digits=10) [1] 1087.003489 But note also: print(p, digits=20) [1]

Re: [R] as.numeric looses precision

2015-07-02 Thread MacQueen, Don
Although Kehl and Petr have already answered the question, I would suggest this as the simplest way to understand what is going on: p - 1087.003489 print( as.numeric(p) , digits=16) [1] 1087.003489 When R prints numbers, it follows various rules regarding how many decimal places to display.

Re: [R] as.numeric looses precision

2015-07-02 Thread Calin Uioreanu
Hello, There's a difference between the displayed value and the internally stored. You could use options(digits=10), but this is a global option, and will affect all future numerical output. default value is 7 p - 1087.003489 as.numeric(p, digits=6) [1] 1087.003 options(digits=10) # set

Re: [R] [as.numeric]Convert Category data to Numeric Data

2014-02-02 Thread arun
Hi, as.numeric(iris$Species) iris1 - within(iris,Species -as.numeric(Species)) A.K. I have a small question for converting the category data to numeric data. For example, if we use the iris data in r. we have: str(iris) 'data.frame': 150 obs. of  5 variables:  $ Sepal.Length: num  5.1

[R] as.numeric() generates NAs inside an apply call, but fine outside of it

2012-01-09 Thread Chris Beeley
Hello- I have rather a messy SPSS file which I have imported to R, I've dput'd some of the columns at the end of this message. I wish to get rid of all the labels and have numeric values using as.numeric. The funny thing is it works like this: as.numeric(mydata[,2]) # generates correct

Re: [R] as.numeric() generates NAs inside an apply call, but fine outside of it

2012-01-09 Thread peter dalgaard
On Jan 9, 2012, at 15:11 , Chris Beeley wrote: Hello- I have rather a messy SPSS file which I have imported to R, I've dput'd some of the columns at the end of this message. I wish to get rid of all the labels and have numeric values using as.numeric. The funny thing is it works like

Re: [R] as.numeric() generates NAs inside an apply call, but fine outside of it

2012-01-09 Thread Chris Beeley
Perfect, many thanks for explanation and correct line of code. On 09/01/2012 14:29, peter dalgaard wrote: as.data.frame(lapply(mydata, as.numeric)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

Re: [R] as.numeric() generates NAs inside an apply call, but fine outside of it

2012-01-09 Thread Petr PIKAL
Hi Hello- I have rather a messy SPSS file which I have imported to R, I've dput'd some of the columns at the end of this message. I wish to get rid of all the labels and have numeric values using as.numeric. The funny thing is it works like this: as.numeric(mydata[,2]) # generates

[R] as.numeric() and POSIXct format

2011-08-24 Thread Agustin Lobo
Hi! I'm confused by this: as.numeric(as.POSIXct(518400,origin=2001-01-01)) [1] 978822000 I guess the problem is that as.numeric() assumes a different origin, but cannot find any default origin. How can I get back the seconds from the POSIXct format? In other words, which the inverse

Re: [R] as.numeric() and POSIXct format

2011-08-24 Thread Justin Haynes
as.POSIXct(518400,origin='2001-01-01') [1] 2001-01-07 PST as.POSIXct(as.numeric(as.POSIXct(518400,origin='2001-01-01')),origin='1970-01-01') [1] 2001-01-07 08:00:00 PST On Wed, Aug 24, 2011 at 9:22 AM, Agustin Lobo agustin.l...@ija.csic.eswrote: Hi! I'm confused by this:

[R] as.numeric

2011-07-12 Thread Jessica Lam
Dear R user, After I imported data (csv format) in R, I called it out. But it is in non-numeric format. Then using as.numeric function. However, the output is really awful ! PE[1,90:99] V90 V91 V92 V93 V94 V95 V96

Re: [R] as.numeric

2011-07-12 Thread Sarah Goslee
Jessica, This would be easier to solve if you gave us more information, like str(PE). However, my guess is that your data somewhere has a nonnumeric value in that column, so the entire column is being imported as factor. It's not really awful - R is converting those factor values to their

Re: [R] as.numeric

2011-07-12 Thread Jim Lemon
On 07/12/2011 06:38 PM, Jessica Lam wrote: Dear R user, After I imported data (csv format) in R, I called it out. But it is in non-numeric format. Then using as.numeric function. However, the output is really awful ! PE[1,90:99] V90 V91 V92 V93

Re: [R] as.numeric

2011-07-12 Thread Rainer Schuermann
It may be helpful to make sure that, in the dialog that pops up when saving a spreadsheet to CSV, the option Save cell content as shown is checked - that would leave numbers as numbers, not wrapping them in . That has helped me at least in a similar situation! Rgds, Rainer On Tuesday 12 July

Re: [R] as.numeric

2011-07-12 Thread Jessica Lam
It works well. Thanks so much. -- View this message in context: http://r.789695.n4.nabble.com/as-numeric-tp3661739p3662671.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

Re: [R] R as.numeric()

2011-05-25 Thread Lutz Fischer
Thanks a lot for both replies. If I setup the option as proposed everything works as I wanted it to. I guess as.character would work as well. Only then I guess I would need to loop through the data frame. Lutz On 24/05/11 22:42, Ista Zahn wrote: This is a FAQ:

Re: [R] R as.numeric()

2011-05-25 Thread David Winsemius
On May 25, 2011, at 7:25 AM, Lutz Fischer wrote: Thanks a lot for both replies. If I setup the option as proposed everything works as I wanted it to. I guess as.character would work as well. Only then I guess I would need to loop through the data frame. as.character is vectorized. You

[R] R as.numeric()

2011-05-24 Thread Lutz Fischer
Hi, I have a bit of a problem with as.numeric or as.double. I read in an excel-file (either xlsx::read.xlsx2 or gdata::read.xls). Select a subset and then try to make it numeric: # read in the excel-file alldata-read.xlsx2(input.xls,1) # select the subset s-subset(alldata,

Re: [R] R as.numeric()

2011-05-24 Thread David Scott
On 25/05/2011 9:20 a.m., Lutz Fischer wrote: Hi, I have a bit of a problem with as.numeric or as.double. I read in an excel-file (either xlsx::read.xlsx2 or gdata::read.xls). Select a subset and then try to make it numeric: # read in the excel-file alldata-read.xlsx2(input.xls,1) # select

Re: [R] R as.numeric()

2011-05-24 Thread Timothy Bates
On 24 May 2011, at 10:20 PM, Lutz Fischer wrote: n-data.matrix(s); s[1,2] [1] 30.94346629 # 3136 Levels: 0.026307482 turned into: n[1,2] [1] 3020 Dear Lutz, “3020” is the factor level associated with 30.94346629, in turn generated by importing with strings in the column Try passing

Re: [R] R as.numeric()

2011-05-24 Thread Ista Zahn
This is a FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f Please try there before posting a question to the list. Best, Ista On Tue, May 24, 2011 at 5:33 PM, David Scott d.sc...@auckland.ac.nz wrote: On 25/05/2011 9:20 a.m., Lutz Fischer wrote: Hi,

[R] as.numeric is truncating!

2009-12-29 Thread ticspd
I am trying to convert a string to a double using as.numeric However, R is truncating the results! Options(digits) is set to 7. Can anyone shed some light on this? Thanks! b[1] [1] 116.28125 summary(b[1]) Length Class Mode 1 character character c - as.numeric(b[1])

Re: [R] as.numeric is truncating!

2009-12-29 Thread Berend Hasselman
ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the results! Options(digits) is set to 7. Can anyone shed some light on this? Thanks! b[1] [1] 116.28125 summary(b[1]) Length Class Mode 1 character

Re: [R] as.numeric is truncating!

2009-12-29 Thread ticspd
ah perfect .. digits = 8 is actually 8 digits TOTAL, not 8 digits after the decimal point! setting the default to 15 works for me thank you! Berend Hasselman wrote: ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the results!

Re: [R] as.numeric is truncating!

2009-12-29 Thread Peter Dalgaard
ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the results! No it isn't! As someone phrased it recently, there's a difference between an object and the display of an object. Ceci n'est pas une pipe. Options(digits) is set to 7. So

Re: [R] as.numeric is truncating!

2009-12-29 Thread ticspd
thank you. and for those who didn't get the reference: http://en.wikipedia.org/wiki/Ren%C3%A9_Magritte http://en.wikipedia.org/wiki/Ren%C3%A9_Magritte Peter Dalgaard wrote: ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the

Re: [R] as.numeric in data.frame, but only where it is possible

2008-11-27 Thread Héctor Villalobos
Hello, On 26 Nov 2008 at 22:53, Kinoko wrote: Hi, I would like to convert my character sequences in my matrix/ data.frame into numeric where it is possible. I would also like to retain my alphabetic character strings in their original forms. 5.15.1 hm hm k-matrix(c(aa,

Re: [R] as.numeric in data.frame, but only where it is possible

2008-11-27 Thread hadley wickham
On Thu, Nov 27, 2008 at 12:53 AM, Kinoko [EMAIL PROTECTED] wrote: Hi, I would like to convert my character sequences in my matrix/ data.frame into numeric where it is possible. I would also like to retain my alphabetic character strings in their original forms. 5.15.1 hm hm

[R] as.numeric in data.frame, but only where it is possible

2008-11-26 Thread Kinoko
Hi, I would like to convert my character sequences in my matrix/ data.frame into numeric where it is possible. I would also like to retain my alphabetic character strings in their original forms. 5.15.1 hm hm k-matrix(c(aa, bb, 1,2, 4.3, 0), nrow=2) mode(k) - numeric # ln1 coerces

[R] as.numeric(.) returns 0

2008-06-12 Thread Paul Johnson
In R version 2.7.0 (2008-04-22) as.numeric(.) returns zero. as.numeric(.) [1] 0 This must be a bug. Splus and previous versions of R (= 2.6.0) return NA, as you might expect. I'm running R version 2.7.0 (2008-04-22) on Windows XP. Paul _

Re: [R] as.numeric(.) returns 0

2008-06-12 Thread Karl Ove Hufthammer
Paul Johnson: In R version 2.7.0 (2008-04-22) as.numeric(.) returns zero. as.numeric(.) [1] 0 Seems to be fixed already. In R version 2.7.0 Patched (2008-06-12 r45898): $ as.numeric(.) [1] NA Warning message: NAs introduced by coercion -- Karl Ove Hufthammer

Re: [R] as.numeric(.) returns 0

2008-06-12 Thread Peter Dalgaard
Paul Johnson wrote: In R version 2.7.0 (2008-04-22) as.numeric(.) returns zero. as.numeric(.) [1] 0 This must be a bug. Splus and previous versions of R (= 2.6.0) return NA, as you might expect. I'm running R version 2.7.0 (2008-04-22) on Windows XP. I suspect that this got

[R] as.numeric with tclvalue redux

2008-03-24 Thread Erin Hodgess
Hi again R People: This works fine: library(tcltk) a - tclVar(4.5) as.numeric(tclvalue(a)) [1] 4.5 #But if you have: b - tclVar(pi) as.numeric(tclvalue(b)) [1] NA Warning message: NAs introduced by coercion Is anyone aware of a way around this, please? thanks, Erin -- Erin Hodgess

Re: [R] as.numeric with tclvalue redux

2008-03-24 Thread Sundar Dorai-Raj
Erin Hodgess said the following on 3/24/2008 10:39 AM: Hi again R People: This works fine: library(tcltk) a - tclVar(4.5) as.numeric(tclvalue(a)) [1] 4.5 #But if you have: b - tclVar(pi) as.numeric(tclvalue(b)) [1] NA Warning message: NAs introduced by coercion Is anyone aware

Re: [R] as.numeric with tclvalue redux

2008-03-24 Thread Peter Dalgaard
Erin Hodgess wrote: Hi again R People: This works fine: library(tcltk) a - tclVar(4.5) as.numeric(tclvalue(a)) [1] 4.5 #But if you have: b - tclVar(pi) as.numeric(tclvalue(b)) [1] NA Warning message: NAs introduced by coercion Is anyone aware of a way around

Re: [R] as.numeric with tclvalue redux

2008-03-24 Thread Erin Hodgess
Thank you! On 3/24/08, Peter Dalgaard [EMAIL PROTECTED] wrote: Erin Hodgess wrote: Hi again R People: This works fine: library(tcltk) a - tclVar(4.5) as.numeric(tclvalue(a)) [1] 4.5 #But if you have: b - tclVar(pi) as.numeric(tclvalue(b)) [1] NA Warning message:

[R] as.numeric rounds up

2008-02-01 Thread Monica Pisica
Hi list, It seems that as.numeric is rounding up my numbers that are in a character format. Example: a [1] 776554.45 776985.31 776076.03 776092.01 776151.42 776276.97 b - as.numeric(a) b [1] 776554.4 776985.3 776076.0 776092.0 776151.4 776277.0 I've tried as.numeric(a,2) and

Re: [R] as.numeric rounds up

2008-02-01 Thread Henrique Dallazuanna
options(digits=10) b or just print(b, 10) On 01/02/2008, Monica Pisica [EMAIL PROTECTED] wrote: Hi list, It seems that as.numeric is rounding up my numbers that are in a character format. Example: a [1] 776554.45 776985.31 776076.03 776092.01 776151.42 776276.97 b -

Re: [R] as.numeric rounds up - Thanks!

2008-02-01 Thread Monica Pisica
So this is only a cosmetic printing and actually my numbers do have 2 decimal numbers . Thanks, Monica Date: Fri, 1 Feb 2008 16:27:00 -0200 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [R] as.numeric rounds up CC: r-help@r-project.org options(digits=10) b or just

[R] as.numeric(FALSE) fails after loading the Matrix package

2007-10-03 Thread Bernd Weiss
Dear all, is this a bug? as.numeric(FALSE) [1] 0 library(Matrix) Loading required package: lattice as.numeric(FALSE) Error in UseMethod(as.double) : no applicable method for as.double Regards, Bernd version _ platform i386-pc-mingw32 arch i386 os

Re: [R] as.numeric(FALSE) fails after loading the Matrix package

2007-10-03 Thread Bernd Weiss
Bernd Weiss schrieb: Dear all, is this a bug? as.numeric(FALSE) [1] 0 library(Matrix) Loading required package: lattice as.numeric(FALSE) Error in UseMethod(as.double) : no applicable method for as.double After doing a complette reinstallation (uninstalling R, deleting all