[英]R reading values of numeric field in file wrongly
R錯誤地從文件中讀取值。 可以通過以下示例檢查此語句是否正確:
這里是說明問題區域的示例圖片/快照
(1)將以下10個數字復制粘貼到測試文件(sample.csv)中
1000522010609612
1000522010609613
1000522010609614
1000522010609615
1000522010609616
1000522010609617
971000522010609612
1501000522010819466
971000522010943717
1501000522010733490
(2)使用read.csv將這些內容讀入R
X <- read.csv("./test.csv", header=FALSE)
(3)打印輸出
print(head(X, n=10), digits=22)
我得到的輸出是
V1
1 1000522010609612.000000
2 1000522010609613.000000
3 1000522010609614.000000
4 1000522010609615.000000
5 1000522010609616.000000
6 1000522010609617.000000
7 971000522010609664.000000
8 1501000522010819584.000000
9 971000522010943744.000000
10 1501000522010733568.000000
問題在於第7、8、9、10行不正確(請檢查我們之前考慮的樣本10個數字)。
可能是什么問題呢? R終端是否缺少某些設置?
你可以試試
library(bit64)
x <- read.csv('sample.csv', header=FALSE, colClasses='integer64')
x
# V1
#1 1000522010609612
#2 1000522010609613
#3 1000522010609614
#4 1000522010609615
#5 1000522010609616
#6 1000522010609617
#7 971000522010609612
#8 1501000522010819466
#9 971000522010943717
#10 1501000522010733490
如果您加載bit64
,那么你也可以嘗試fread
從data.table
library(data.table)
x1 <- fread('sample.csv')
x1
# V1
#1: 1000522010609612
#2: 1000522010609613
#3: 1000522010609614
#4: 1000522010609615
#5: 1000522010609616
#6: 1000522010609617
#7: 971000522010609612
#8: 1501000522010819466
#9: 971000522010943717
#10: 1501000522010733490
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.