47233

R seq function produces wrong results [closed]

Question:

It seems that one of my machines produces wrong results for seq function while another machine or the online r-fiddle (<a href="http://www.r-fiddle.org" rel="nofollow">http://www.r-fiddle.org</a>) interpreter give expected results. On the machine in question following happens:

seq(from = 1, to = 1.1, by = 0.01) [1] 1.0 1.0 1.0 1.0 1.0 1.0 1.1 1.1 1.1 1.1 1.1

Changing the command slightly returns expected result

seq(from = 0.99, to = 1.1, by = 0.01) [1] 0.99 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10

As soon as I cross the "1" threshold, the wrong result occurs, e.g. same when I do from = 2.95 to = 3.1, etc. Not sure how to find an answer as I couldn't replicate the problem on my other machine or on r-fiddle. The problem persists even after restarting the pc.

R version 3.1.3 (2015-03-09)<br /> Platform: x86_64-w64-mingw32/x64 (64-bit)<br /> Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:<br /> [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252<br /> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C<br /> [5] LC_TIME=German_Germany.1252

Answer1:

You have set the digits option too low:

options(digits=2) seq(from = 1, to = 1.1, by = 0.01) #[1] 1.0 1.0 1.0 1.0 1.0 1.1 1.1 1.1 1.1 1.1 1.1 options(digits=7) seq(from = 1, to = 1.1, by = 0.01) #[1] 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10

Recommend

  • using gsub to modify output of xtable command
  • Removing rows based on dependent conditions
  • X and Y axis intersect at 0 [duplicate]
  • linear regression in R without copying data in memory?
  • Cycling through decimal values
  • R seq function produces wrong results [closed]
  • Plotting longer tick marks at particular y-axis values
  • Tensorboard: No graph definition files were found.
  • Amazon api not deleting my products from inventory
  • How to parse CSV file with PHP and insert into MySQL database? [closed]
  • R— repeating linear regression in a large dataset
  • regexp add space after period but not when period represents a decimal or letter abbreviation?
  • Adding a system dependency to Maven
  • What are the valid types for a WebGL vertex shader attribute?
  • How to Launch Google TV Panoramio Android Sample in Emulator
  • How can I handle Castor unmarshaling of SOAP messages when the namespace is defined inside the opera
  • Adding and Subtracting with Javascript and JSON
  • EXCEL Multiple Ranges - need different answers for each range
  • group values contaning np.nan in intervals
  • NumberFormat problem
  • Is there a way to call library thread-local init/cleanup on thread creation/destruction?
  • Classic ASP URL Rewriting
  • Efficient User-Agent Regex to find Safari in Python
  • Primefaces lazy datascroller calling load twice
  • How to access meteor package name inside package?
  • Rest Services conventions
  • SonarQube: Cannot deactivate rule with missing quality profile
  • Bad request using file_get_contents for PUT request in PHP
  • Jenkins: How To Build multiple projects from a TFS repository?
  • How do I fake an specific browser client when using Java's Net library?
  • Java applet as stand-alone Windows application?
  • SSO with signing and signature validation doesn't work
  • Fill an image in a square container while keeping aspect ratio
  • Deserializing XML into class C#
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Apache 2.4 - remove | delete | uninstall
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • costura.fody for a dll that references another dll
  • Reading document lines to the user (python)