1

我对 R (和堆栈溢出)完全陌生,并且有以下问题。我有一个包含环境变量的 excel 电子表格,我需要将其转换为 netCDF 文件 (.nc)。我在 R 上找到了手册,但无法实施。有没有人知道一个好的分步指南的来源或能够帮助我?

到目前为止,我已经设法做到以下几点

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 )

我正在努力将数据(对于 O18(氧同位素,excel 文件中的一列))从 excel 文件中获取到这个新的 .nc 文件中。我知道我需要ncvar_put,但我不明白它需要什么或做什么。

excel表格中的数据格式如下:

Group Site Country Longitude Latitude Date O18 ...

当然,有值,但我只对 O18 和日期列感兴趣。

4

0 回答 0