Using R to download zipped data file, extract, and import .csv

前端 未结 3 1844
無奈伤痛
無奈伤痛 2020-12-06 01:07

I am trying to download and extract a .csv file from a webpage using R.

This question is a duplicate of Using R to download zipped data file, extrac

3条回答
  •  情深已故
    2020-12-06 01:11

    It's almost everything ok. In this case you only need to specify that it's a comma separated file, eg using sep="," in read.table:

    temp <- tempfile()
    download.file("http://api.worldbank.org/v2/en/country/gbr?downloadformat=csv", 
                  temp)
    con <- unz(temp, "gbr_Country_en_csv_v2.csv")
    dat <- read.table(con, header=T, skip=2, sep=",")
    unlink(temp)
    

    With this little change i can import your csv smoothly.

    HTH, Luca

提交回复
热议问题