使用 R 下载 gzipped 数据文件、提取和导入数据 [英] Using R to download gzipped data file, extract, and import data
本文介绍了使用 R 下载 gzipped 数据文件、提取和导入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
跟进这个问题:如何使用 R 下载和解压缩 gzip 文件?例如(来自 UCI 机器学习存储库),我有一个 保险数据文件.如何使用 R 下载它?
A follow up to this question: How can I download and uncompress a gzipped file using R? For example (from the UCI Machine Learning Repository), I have a file of insurance data. How can I download it using R?
这里是数据网址:http://archive.ics.uci.edu/ml/databases/tic/tic.tar.gz
.
推荐答案
我喜欢 Ramnath 的方法,但我会像这样使用临时文件:
I like Ramnath's approach, but I would use temp files like so:
tmpdir <- tempdir()
url <- 'http://archive.ics.uci.edu/ml/databases/tic/tic.tar.gz'
file <- basename(url)
download.file(url, file)
untar(file, compressed = 'gzip', exdir = tmpdir )
list.files(tmpdir)
list.files()
应该产生如下内容:
[1] "TicDataDescr.txt" "dictionary.txt" "ticdata2000.txt" "ticeval2000.txt" "tictgts2000.txt"
如果您需要为大量文件自动执行此过程,您可以解析它.
which you could parse if you needed to automate this process for a lot of files.
这篇关于使用 R 下载 gzipped 数据文件、提取和导入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文