Description Usage Arguments Value Examples
nctoarray
is used to create a three-dimensional array
containing data from a .nc file.
1 |
filein |
A character string with the full path name of the nc file. Tilde-expansion is performed. |
varid |
The variable to be read from the ncfile. Can be a string with the name of the variable or an object of class ncvar4. If left unspecified, the function will determine if there is only one variable in the file and, if so, read from that. If left unspecified and there are multiple variables in the file, an error is generated. |
a three-dimensional array of the specified variable, permuted to dimension order 2, 1, 3.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # ========= Create nc file of random data and save to disk ============= #
longs <- ncdim_def(name="lon", units = "degrees_east",
vals = seq(1,10,1),longname="longitude")
lats <- ncdim_def(name="lat", units = "degrees_north",vals=seq(1,10,1),
longname="latitude")
times <- ncdim_def(name="time",units="hours since 1983-01-01 00:00:00",
vals=c(101:110))
mydata <-ncvar_def(name="Random data", units="mm", dim = list(longs, lats, times))
ncnew <- nc_create(filename="Random.nc", mydata)
ncvar_put(ncnew, mydata, vals = array(rnorm(10000), dim = c(10,10,10)))
nc_close(ncnew)
# ========= Read in as array ============================= #
arr <- nctoarray("Random.nc", varid = "Random data")
dim(arr)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.