R: reading a binary file that is zipped

后端 未结 1 1335
天命终不由人
天命终不由人 2020-12-19 07:03

I am trying to parse some online weather data with R. The data is a binary file that has been gzipped. An example file is:

ftp://ftp.cpc.ncep.noaa.gov/precip/C

相关标签:
1条回答
  • 2020-12-19 07:34

    Try this:

    R> remfname <- "ftp://ftp.cpc.ncep.noaa.gov/precip/CPC_UNI_PRCP/GAUGE_GLB/V1.0/2005/PRCP_CU_GAUGE_V1.0GLB_0.50deg.lnx.20050101.gz"
    R> locfname <- "/tmp/data.gz"
    R> download.file(remfname, locfname)
    trying URL 'ftp://ftp.cpc.ncep.noaa.gov/precip/CPC_UNI_PRCP/GAUGE_GLB/V1.0/2005/PRCP_CU_GAUGE_V1.0GLB_0.50deg.lnx.20050101.gz'
    ftp data connection made, file length 179058 bytes
    opened URL
    ==================================================
    downloaded 174 Kb
    
    R> con <- gzcon(file(locfname, "rb"))
    R> myPoints <- readBin(con, real(), n=1e6, size = 4, endian = "little")
    R> close(con)
    R> str(myPoints)
     num [1:518400] 0 0 0 0 0 0 0 0 0 0 ...
    R> 
    
    0 讨论(0)
提交回复
热议问题