R: "read" 来自 URL 的 txt 文件
R: "read" a txt file from a URL
我想看看是否可以直接从 url 加载(到 R)txt 文件,而不是先下载再导入。
我在这里遇到了这个 post:Access a URL and read Data with R
显然可以使用 csv 文件执行此操作。是否可以对 txt 文件做同样的事情?
我尝试将此 Whosebug post 中的代码改编为以下网站:https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt
myfile <- read.txt(url("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt"))
但是好像没有效果。
我是不是做错了什么?或者无法直接从 url 将 txt 文件加载到 R 中?
谢谢
尝试使用 data.table
函数 fread()
(加载数据最快的函数之一):
library(data.table)
#Load
myfile <- fread("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt")
输出(一些行):
head(myfile)
V1
1: 0.12206400
2: 0.04719682
3: -0.01833035
4: -0.08194958
5: -0.13422158
6: -0.18542675
您可以使用 as.data.frame()
或:
将其包装为数据框
#Load 2
myfile <- fread("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt",data.table = F)
问题是 read.txt
不存在。
?read.txt
No documentation for ‘read.txt’ in specified packages and libraries:
you could try ‘??read.txt’
应该是read.table
(不需要任何包)
myfile <- read.table(url("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt"))
-输出
dim(myfile)
#[1] 10000 1
head(myfile)
# V1
#1 0.12206400
#2 0.04719682
#3 -0.01833035
#4 -0.08194958
#5 -0.13422158
#6 -0.18542675
我想看看是否可以直接从 url 加载(到 R)txt 文件,而不是先下载再导入。
我在这里遇到了这个 post:Access a URL and read Data with R
显然可以使用 csv 文件执行此操作。是否可以对 txt 文件做同样的事情?
我尝试将此 Whosebug post 中的代码改编为以下网站:https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt
myfile <- read.txt(url("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt"))
但是好像没有效果。
我是不是做错了什么?或者无法直接从 url 将 txt 文件加载到 R 中?
谢谢
尝试使用 data.table
函数 fread()
(加载数据最快的函数之一):
library(data.table)
#Load
myfile <- fread("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt")
输出(一些行):
head(myfile)
V1
1: 0.12206400
2: 0.04719682
3: -0.01833035
4: -0.08194958
5: -0.13422158
6: -0.18542675
您可以使用 as.data.frame()
或:
#Load 2
myfile <- fread("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt",data.table = F)
问题是 read.txt
不存在。
?read.txt
No documentation for ‘read.txt’ in specified packages and libraries: you could try ‘??read.txt’
应该是read.table
(不需要任何包)
myfile <- read.table(url("https://mantas.info/wp/wp-content/uploads/simple_esn/MackeyGlass_t17.txt"))
-输出
dim(myfile)
#[1] 10000 1
head(myfile)
# V1
#1 0.12206400
#2 0.04719682
#3 -0.01833035
#4 -0.08194958
#5 -0.13422158
#6 -0.18542675