尝试将其读入 R 环境时,txt 文件有什么问题?
What is the problem with a txt file when trying to read this into R environment?
我正在尝试将 txt 文件读入 R 环境。
我不明白它有什么问题以及为什么我无法将 txt 读入列中。有人可以向我解释这里的实际问题是什么吗?因为这将使我能够在互联网上正确搜索。但首先我必须了解它的问题。
这是我拥有的数据类型。
structure(list(dateRep.day.month.year.cases.deaths.countriesAndTerritories.geoId.countryterritoryCode.popData2018.continentExp = c("01/06/2020,1,6,2020,680,8,Afghanistan,AF,AFG,37172386,Asia",
"31/05/2020,31,5,2020,866,3,Afghanistan,AF,AFG,37172386,Asia",
"30/05/2020,30,5,2020,623,11,Afghanistan,AF,AFG,37172386,Asia",
"29/05/2020,29,5,2020,580,8,Afghanistan,AF,AFG,37172386,Asia",
"28/05/2020,28,5,2020,625,7,Afghanistan,AF,AFG,37172386,Asia",
"27/05/2020,27,5,2020,658,1,Afghanistan,AF,AFG,37172386,Asia"
)), row.names = c(NA, 6L), class = "data.frame")
我试图用这段代码将 table 读入 R:
test <- read.delim("download.txt", header = TRUE, sep = "\t")
还有这段代码:
read.table(download.txt, header = TRUE, sep = ",")
是否有一种 tidyverse 的方式来读取带有分隔列的 txt 文件?
我怀疑问题是 download.txt
在您写的最后一行中应该是 "download.txt"
。您的数据以逗号分隔,因此您可以使用 read.table("download.txt", header = TRUE, sep = ",")
,或者简单地使用带有默认参数的 read.csv("download.txt")
。
这是我拥有的数据类型。
structure(list(dateRep.day.month.year.cases.deaths.countriesAndTerritories.geoId.countryterritoryCode.popData2018.continentExp = c("01/06/2020,1,6,2020,680,8,Afghanistan,AF,AFG,37172386,Asia",
"31/05/2020,31,5,2020,866,3,Afghanistan,AF,AFG,37172386,Asia",
"30/05/2020,30,5,2020,623,11,Afghanistan,AF,AFG,37172386,Asia",
"29/05/2020,29,5,2020,580,8,Afghanistan,AF,AFG,37172386,Asia",
"28/05/2020,28,5,2020,625,7,Afghanistan,AF,AFG,37172386,Asia",
"27/05/2020,27,5,2020,658,1,Afghanistan,AF,AFG,37172386,Asia"
)), row.names = c(NA, 6L), class = "data.frame")
我试图用这段代码将 table 读入 R:
test <- read.delim("download.txt", header = TRUE, sep = "\t")
还有这段代码:
read.table(download.txt, header = TRUE, sep = ",")
是否有一种 tidyverse 的方式来读取带有分隔列的 txt 文件?
我怀疑问题是 download.txt
在您写的最后一行中应该是 "download.txt"
。您的数据以逗号分隔,因此您可以使用 read.table("download.txt", header = TRUE, sep = ",")
,或者简单地使用带有默认参数的 read.csv("download.txt")
。