【发布时间】:2020-06-22 15:29:08
【问题描述】:
我一年有 365 个 .nc 文件,每个文件都包含一天的土壤水分信息。我想从三个不同的坐标中提取土壤水分信息,并将它们写入给定年份的三个 csv 文件。目前,我能够将所有 365 .nc 文件转换为 365 csv 文件,如附加代码中给出的。下一步怎么走?
rm(list = ls())
library(raster)
library(ncdf4)
ptf <- "D://SMOS_ECV_SM//SMOS_ECV_SM//ECV_SM_Data_1978_2010//1978"
setwd(ptf) # change your working directory
lf <- list.files(pattern="[.]nc$") # list of files ending in .nc
for(i in lf){
nc.brick <- brick(i)
nc.df <- as.data.frame(nc.brick[[1]], xy=T)
write.csv(nc.df, sub("[.]nc$",".csv",i)) # write to the same file name substituting .nc to .csv
}
【问题讨论】: