我想将CSV格式的数据导入r-studio
数据是这样的
1732.7193603515625 ,7825.7729492187500
1732.7191162109375 ,7825.7714843750000
1732.7191162109375 ,7825.7714843750000
1732.7191162109375 ,7825.7714843750000
1732.7189941406250 ,7825.7709960937500
1732.7189941406250 ,7825.7709960937500
1732.7189941406250 ,7825.7709960937500
1732.7193603515625 ,7825.7709960937500
但是当我使用此代码导入时
library(readr)
GPSDATA_Copy1 <- read_csv("D:/Desktop/GPSDATA - Copy1.TXT",
col_types = cols(`lat` = col_double(),
`lon` = col_double()))
View(GPSDATA_Copy1)
但它以较低的精度导入此格式
1732.719,7825.772 1732.719,7825.771 1732.719,7825.771 1732.719,7825.771 1732.718,7825.770 1732.718,7825.770 1732.718,7825.770 1732.719,7825.770
如何解决这个问题
答案 0 :(得分:3)
RStudio中的查看器仅显示几位数字。但是,它们都是正确导入的,您可以使用format
进行测试,如以下示例所示。
library(readr)
tmp <- tempfile()
cat("1732.7193603515625 ,7825.7729492187500
1732.7191162109375 ,7825.7714843750000
1732.7191162109375 ,7825.7714843750000
1732.7191162109375 ,7825.7714843750000
1732.7189941406250 ,7825.7709960937500
1732.7189941406250 ,7825.7709960937500
1732.7189941406250 ,7825.7709960937500
1732.7193603515625 ,7825.7709960937500",
file = tmp)
test <- read_csv(tmp, col_names = c("A", "B"))
#> Parsed with column specification:
#> cols(
#> A = col_double(),
#> B = col_double()
#> )
format(test[[1, ]], nsmall = 10)
#> [1] "1732.7193603516" "1732.7191162109" "1732.7191162109" "1732.7191162109"
#> [5] "1732.7189941406" "1732.7189941406" "1732.7189941406" "1732.7193603516"