[R] Convert ncdf data to dataframe

MacQueen, Don macqueen1 at llnl.gov
Thu Jun 2 17:04:26 CEST 2016


There's a pretty good chance this question has been previously asked and
answered on the R-sig-geo mailing list (though I don't know for sure).

In addition, entering

  "R convert ncdf to data frame"

in a web search returned some possibilities, the first of which (for me)
was

  http://geog.uoregon.edu/bartlein/courses/geog607/Rmd/netCDF_01.htm

and partway down that page is an entry,

  "Get a single time slice of the data, create an R data frame, and write
a .csv file"

which does indeed have some examples of how to convert to a data frame.


-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 6/2/16, 1:42 AM, "R-help on behalf of Miluji Sb"
<r-help-bounces at r-project.org on behalf of milujisb at gmail.com> wrote:

>Dear all,
>
>I have used the following code to read in a ncdf file
>
>library(chron)
>library(lattice)
>library(ncdf4)
>library(data.table)
>
>ncname <- ("/file_path")
>ncfname <- paste(ncname, ".nc", sep = "")
>dname <- "ssl"  # note: tmp means temperature (not temporary)
>
>ncin <- nc_open(ncfname)
>print(ncin)
>
>The attributes of the file are:
>
>     4 variables (excluding dimension variables):
>        double longitude[row]
>            long_name: longitude
>            units: degrees_east
>            standard_name: longitude
>        double latitude[row]
>            long_name: latitude
>            units: degrees_north
>            standard_name: latitude
>        double ssl[col,row]
>            long_name: storm surge level
>            units: m
>            _FillValue: -99999
>            scale_factor: 1
>            add_offset: 1
>        float RP[col]
>            long_name: return period
>            units: yr
>            Contents: The RPs have been estimated following the Peak Over
>Threshold Method (see reference below)
>            Starting date: 01-Dec-2009
>            End date: 30-Nov-2099 21:00:00
>     2 dimensions:
>        col  Size:8
>        row  Size:2242
>
>I would like to convert the data into a dataframe by longitude and
>latitude. Is that possible? Thank you!
>
>Sincerely,
>
>Milu
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list