I want to read a data file into R. The data format is 4e20.5
in Fortran style.
-0.12652E-03 0.18851E-03 0.91379E-04 0.20404E-04
If possible, please show me how to get the numbers with read.table
function. Any answer will be appreciated.
Posting as an answer rather than a comment for formatting reasons: if your file really has just this text, read.table()
should work fine (as pointed out in the comments), eg:
read.table(text=" -0.12652E-03 0.18851E-03 0.91379E-04 0.20404E-04")
## V1 V2 V3 V4
## 1 -0.00012652 0.00018851 9.1379e-05 2.0404e-05
All we can do is speculate that there is something odd about the separators in your file. Without a link to the file, we probably can't do more than speculate.
Note that the print formatting has changed (eg -0.12652E-03 is now printed as -0.00012652), but the numbers are read correctly (see ?options
and search for scipen
).
请原谅我对 R 的无知。现在我解决了这个问题:
data <- read.fwf("data.txt",width=rep(20,4))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.