Thanks for the quick response. Read the FAQ. If i want to keep the values in R the same as when inputed should i be converting the data to a different type - i.e. Not numeric?
Sent from my iPhone On Oct 11, 2011, at 4:46 AM, Jim Holtman <jholt...@gmail.com> wrote: > FAQ 7.31 > > Sent from my iPad > > On Oct 11, 2011, at 1:07, Mark Harrison <harrisonma...@gmail.com> wrote: > >> I am having a problem with extra digits being added to my data which I think >> is a result of how I am converting my data.frame data to xts. >> >> I see the same issue in R v2.13.1 and RStudio version 0.94.106. >> >> I am loading historical foreign exchange data in via csv files or from a sql >> server database. In both cases there are no extra digits and the original >> data looks like the following: >> >> Date Open High Low Close >> 1 2001-01-03 1.5021 1.5094 1.4883 1.4898 >> 2 2001-01-04 1.4897 1.5037 1.4882 1.5020 >> 3 2001-01-05 1.5020 1.5074 1.4952 1.5016 >> 4 2001-01-08 1.5035 1.5104 1.4931 1.4964 >> 5 2001-01-09 1.4964 1.4978 1.4873 1.4887 >> 6 2001-01-10 1.4887 1.4943 1.4856 1.4866 >> >> So for 2001-01-03 the Open value is 1.5021 with only 4 digits after the >> decimal place - i.e. .5021. >> >> I then proceed to do the following in R to convert the 'british pound' data >> above from data.frame to xts: >> >> Require(quantmod) >> rownames(gbp) <- gbp$Date >> head(gbp) >> >> Open High Low Close >> 2001-01-03 1.5021 1.5094 1.4883 1.4898 >> 2001-01-04 1.4897 1.5037 1.4882 1.5020 >> 2001-01-05 1.5020 1.5074 1.4952 1.5016 >> 2001-01-08 1.5035 1.5104 1.4931 1.4964 >> 2001-01-09 1.4964 1.4978 1.4873 1.4887 >> 2001-01-10 1.4887 1.4943 1.4856 1.4866 >> >> gbp<- as.xts(gbp[,2:5]) >> class(gbp) >> >> [1] "xts" "zoo" >> >> The data at this point looks ok until you look closer or output the data to >> excel at which point you see the following for the 'Open' 2001-01-03: >> 1.50209999084473 >> >> It is not just the above 'Open' or the first value but all the data points >> contain the extra digits which I think is the original date data and/or row >> numbers that are being tacked on. >> >> My problem is the extra digits being added or whatever I am doing wrong in R >> to cause the extra digits to be added. I need 1.5021 to be 1.5021 and not >> 1.50209999084473. >> >> Thanks for the help. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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 >> and provide commented, minimal, self-contained, reproducible code. ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.