I am completely new to R (and stack overflow) and have the following problem. I have an excel spreadsheet containing environmental variables and I need to convert it to a netCDF file (.nc). I found the manual on R but am not able to implement it. Does anybody know of a source for a good step by step guide or is able to help me?
So far, I've managed to do the following
library(ncdf4)
# Define the dimensions of the .nc file
x <- ncdim_def( "Lon", "degreesE", 0.5:359.5)
y <- ncdim_def( "Lat", "degreesN", as.double(-89:89))
t <- ncdim_def( "Time", "days since 1900-01-01", 1:10, unlim=TRUE)
# Make a variable with those dimensions. (I want O18)
O18 <- ncvar_def("O18", "ppt", list(x,y,t), 1.e30 )
# Create a netCDF file with this variable
ncnew <- nc_create( "O18.nc", O18 )
I am struggling with how to get the data (for O18 (oxygen isotope, a column in the excel file)) from the excel file into this new .nc file. I know I need ncvar_put
, but I don't understand what it needs or does.
Data in the excel sheet is of the form:
Group Site Country Longitude Latitude Date O18 ...
with values, of course, but I am only interested in the columns O18 and Date.