使用 read_table 与 read.table 读取 .txt 文件时的负值到正值
negative to positive value when reading .txt file using read_table vs read.table
我正在尝试读取一个相当大的 txt 文件,但是当我使用 readr 中的 read_table 时,我注意到某些值的负号必须被切断。
library(tidyverse)
library(curl)
curl_download(url = 'https://drive.google.com/uc?export=download&id=1WON53elbMVxAM8yWSg69nuu0cnHjaQdh',
destfile = '/Users/Jay/Desktop/1992_anomaly.txt')
dat1 <- read_table('/Users/Jay/Desktop/1992_anomaly.txt',
col_names = FALSE,
col_types = cols(
X1 = col_integer(),
X2 = col_integer(),
X3 = col_integer(),
X4 = col_double(),
X5 = col_double(),
X6 = col_double()
))
dat1
dat2 <- read.table('/Users/Jay/Desktop/1992_anomaly.txt',
header = FALSE)
head(dat2)
# value from read_table that should be negative
dat1 %>%
filter(
X1 == 12 & X2 == 5 & X3 == 1295
)
# value from read.table that's correct
dat2 %>%
as_tibble() %>%
filter(
V1 == 12 & V2 == 5 & V3 == 1295
)
我可以在 read_table 函数中更改某些内容,还是我需要使用 read_delim 才能正确读取此文件?
尝试使用 readr
中的 read_table2
我正在尝试读取一个相当大的 txt 文件,但是当我使用 readr 中的 read_table 时,我注意到某些值的负号必须被切断。
library(tidyverse)
library(curl)
curl_download(url = 'https://drive.google.com/uc?export=download&id=1WON53elbMVxAM8yWSg69nuu0cnHjaQdh',
destfile = '/Users/Jay/Desktop/1992_anomaly.txt')
dat1 <- read_table('/Users/Jay/Desktop/1992_anomaly.txt',
col_names = FALSE,
col_types = cols(
X1 = col_integer(),
X2 = col_integer(),
X3 = col_integer(),
X4 = col_double(),
X5 = col_double(),
X6 = col_double()
))
dat1
dat2 <- read.table('/Users/Jay/Desktop/1992_anomaly.txt',
header = FALSE)
head(dat2)
# value from read_table that should be negative
dat1 %>%
filter(
X1 == 12 & X2 == 5 & X3 == 1295
)
# value from read.table that's correct
dat2 %>%
as_tibble() %>%
filter(
V1 == 12 & V2 == 5 & V3 == 1295
)
我可以在 read_table 函数中更改某些内容,还是我需要使用 read_delim 才能正确读取此文件?
尝试使用 readr
read_table2