0

我正在尝试学习 R 的 stars 包,并对小插图中的代码有疑问。我的问题的数据可在 stars 包中找到。这是代码:

library(stars)

prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars")
prec = read_ncdf(prec_file, curvilinear = c("lon", "lat"))
## no 'var' specified, using Total_precipitation_surface_1_Hour_Accumulation
## other available variables:
##  time_bounds, lon, lat, time
## No projection information found in nc file. 
##  Coordinate variable units found to be degrees, 
##  assuming WGS84 Lat/Lon.
## Warning in .get_nc_dimensions(dimensions, coord_var = all_coord_var, coords =
## coords, : bounds for time seem to be reversed; reverting them
##plot(prec) ## gives error about unique breaks
## remove NAs, zeros, and give a large number
## of breaks (used for validating in detail)
qu_0_omit = function(x, ..., n = 22) {
  if (inherits(x, "units"))
    x = units::drop_units(na.omit(x))
  c(0, quantile(x[x > 0], seq(0, 1, length.out = n)))
}

在这里我感到困惑。有人可以向我解释为什么 NA 被删除吗?我问是因为我正在使用 NetCDF,并且我相信我需要消除 NA,但我没有收到关于中断的错误。我试图只使用与 NA 相关的部分功能,如下所示:

remove_NAs = function(x) {
  if (inherits(x, "units"))
    x = units::drop_units(na.omit(x))
}

然后做这样的事情:remove_NAs(mydata)但这不起作用。我没有收到错误,但 NA 仍然出现在我的数据集中。我实际上也没有在示例数据集中看到任何 NA,所以我什至不确定要删除什么。有人可以解释这里发生了什么吗?非常感谢。

4

0 回答 0