0

I would like to read a binary file in R. The file is available for download here: just select one of the files, download and unzip. The instructions on how to open the files are at page 6 of this document.

I have tried to adapt some code taken from previous questions, but does not work in my case. Can anyone help?

EDIT:

I see that is crucial to understand the structure of the binary file. That is number of rows and columns. The manual (link above) says that there are 5 variables.
Thus, in R I run:

# read column names
column.names <- readBin("gpcp_v2.2_psg.1979", character(),  n = 5)

Now I need to read the actual data with:

bindata <- readBin(read.filename, integer(),  n = nrows*ncolumns)

However, I do not understand how to retrieve the number of rows of my data in oder to enter the right value for "nrows*ncolumns".

lmo
  • 37,904
  • 9
  • 56
  • 69
Caserio
  • 472
  • 1
  • 3
  • 14
  • http://stackoverflow.com/questions/6154497/r-reading-a-binary-file-that-is-zipped?rq=1 – Jean Feb 27 '17 at 08:59
  • Use `readBin`. The first call will be to read in the header which is 576 bytes. Then the next call will be to read in the real variables (it will start with the 577th byte as it always reads from where you left off). You can read one or more at a time (I suppose the number depends on the file size and how many you want to load in memory). There are lots of examples online, e.g. https://www.tutorialspoint.com/r/r_binary_files.htm – konvas Feb 27 '17 at 09:07
  • The code provided in the comment above gives `Error: unexpected symbol in "trying URL" ` after `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"` – Caserio Feb 27 '17 at 09:08

0 Answers0