# Example data frame
example_df <- data.frame(
lat = c(-35.0, -34.5, -34.0),
lon = c(150.0, 150.5, 151.0),
variable1 = c(0.1, 0.2, 0.3),
variable2 = c(0.4, 0.5, 0.6)
)
# Define units, longnames, and CF standard names
units_list <- list(variable1 = "m", variable2 = "cm")
longnames_list <- list(variable1 = "Variable 1 Longname",
variable2 = "Variable 2 Longname")
cf_standard_names_list <- list(variable1 = "sea_surface_height",
variable2 = "sea_water_temperature")
tf <- tempfile("test.nc")
# Convert example data frame to NetCDF
df_to_netcdf(example_df, tf, global_atts = list(
title = "Example NetCDF",
summary = "This is a test NetCDF file created from an example data frame.",
source = "Example data",
references = "N/A"
), units = units_list, longnames = longnames_list,
cf_standard_names = cf_standard_names_list)
Run the code above in your browser using DataLab