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
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
: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
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]
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.
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
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
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
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
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
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
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
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:
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
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
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
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
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
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:
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
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,
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
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
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,
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])
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
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!
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
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
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,
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
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
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
_
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
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
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
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
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
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:
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
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 -
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
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
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
44 matches
Mail list logo