vignettes/work_with_netcdf.Rmd
work_with_netcdf.Rmd
## here() starts at /home/runner/work/rgeco/rgeco
Read contents of a NetCDF file into a data frame
The variable name needs to be specified. You can obtain it by doing
ncdump -h cwdx80_forcing_halfdeg.nc
in the terminal.
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
df
## # A tibble: 259,200 × 3
## lon lat cwdx80_forcing
## <dbl[1d]> <dbl[1d]> <dbl>
## 1 -180. -89.8 NA
## 2 -179. -89.8 NA
## 3 -179. -89.8 NA
## 4 -178. -89.8 NA
## 5 -178. -89.8 NA
## 6 -177. -89.8 NA
## 7 -177. -89.8 NA
## 8 -176. -89.8 NA
## 9 -176. -89.8 NA
## 10 -175. -89.8 NA
## # ℹ 259,190 more rows
This contains NA
for cells that have no values.
df <- df |>
tidyr::drop_na()
df
## # A tibble: 57,345 × 3
## lon lat cwdx80_forcing
## <dbl[1d]> <dbl[1d]> <dbl>
## 1 -68.8 -55.2 178.
## 2 -67.2 -55.2 167.
## 3 -69.2 -54.8 140.
## 4 -68.8 -54.8 156.
## 5 -68.2 -54.8 155.
## 6 -67.8 -54.8 155.
## 7 -67.2 -54.8 156.
## 8 -66.8 -54.8 388.
## 9 -66.2 -54.8 404.
## 10 -69.2 -54.2 204.
## # ℹ 57,335 more rows