Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
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 <- ""

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
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:


Related questions

Browse Categories