0

My test shows content as below"

"ID"    "Prob"
0   10000
1   8778.9828374645
2   8694.77448972435

I tried to skip the first row so that my content are pure numbers and give them column names instead

data <-
  read.fwf("mydata.txt",
              skip = 1,
              widths= c(18),
              col.names=c("ID", "Prob"),
              strip.white=TRUE
              )

However, the results looks like this (it automatically scientific notation & reserve decimal)

      ID           Prob
      0      1.000000e+04
      1      8778.982e+03

Then I tried not skip the first row and still give them a row name. The number value is good, but there is an extra row of "ID & Prob"

data <-
  read.fwf("mydata.txt",
              widths= c(18),
              col.names=c("ID", "Prob"),
              strip.white=TRUE
              ) 

It looks like

ID      Prob
"ID"    "Prob"
0   10000
1   8778.9828374645

How can I make my load data shows exactly the same as my original text data? (Do not use scientific notation and do not reserve decimal) (Also my data is just column name and pure numbers )

Flora
  • 463
  • 1
  • 15
  • 1
    Run this in your R console `options(scipen = 999)` and try again. – Ronak Shah Aug 14 '20 at 00:26
  • Solved! Thank you so much !!! :) – Flora Aug 14 '20 at 00:28
  • 1
    The second run only looks correct but it's reading as characters rather than as numeric. The first one was read in correctly but R was using the default print options. – IRTFM Aug 14 '20 at 00:29
  • 1
    see also https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal – MichaelChirico Aug 14 '20 at 00:30
  • 1
    Here's an SO search with several well written answers among the various Q&A's. https://stackoverflow.com/search?q=%5Br%5D+print+significant+digits The SO search page lets you sort by rep. – IRTFM Aug 14 '20 at 00:34

0 Answers0