Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)
edited by

"Lots of online csv's are zipped. Is there a way to download, unzip the archive, and load the data to a data.frame using R? #Rstats"

I was also trying to do this today, but ended up just downloading the zip file manually.

I tried something like:

fileName <- "http://www.newcl.org/data/zipfiles/a1.zip"

con1 <- unz(fileName, filename="a1.dat", open = "r")

but I feel as if I'm a long way off. Any thoughts?

1 Answer

0 votes
by
edited by

To download, extract, and import a zipped data file in R, you can do the following:

Create a temporary file to store the file to be downloaded:

temp <- tempfile()

Download the file from the url:

download.file("file url",temp)

To extract the file from temp file and read the data using read.table:

data <- read.table(unz(temp, "file1.dat"))

Remove the temporary file:

unlink(temp)

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...