R语言批处理中国地面气候资料日值数据集(V3.0)
代码分需要的数据项进行
运行不了请删备注
gc()
library(data.table)
setwd("C:\\Users\\D\\Desktop\\SURF_CLI_CHN_MUL_DAY_V3.0") #工作目录
rawpath <- "datasets"#文件夹
temfiles <- list.files(path = rawpath, full.names = T, pattern = "^SURF_CLI_CHN_MUL_DAY-TEM-12001-.*.TXT")#找到形如SURF_CLI_CHN_MUL_DAY-TEM-12001-.的文件
temdata <- rbindlist(lapply(temfiles, fread))[, 1:10]#读取1-10列
setnames(temdata, c("sid", "lat", "long", "elev", "year", "month", "day", "tmean", "tmax", "tmin"))#设置属性名
data <- temdata
fwrite(setorder(data, sid, year, month, day), file = "cmd_raw.csv", quote = T)#保存为原始数据
data <- fread("cmd_raw.csv")#读取原始数据
data[tmean == 32766, tmean := NA]
data[tmax == 32766, tmax := NA]
data[tmin == 32766, tmin := NA]
data[, c("tmean", "tmax", "tmin") := list(tmean * 0.1, tmax * 0.1, tmin * 0.1)]#数据预处理
fwrite(setorder(data, sid, year, month, day), file = "cmd_norm.csv", quote = T)#保持为标准数据
sub <- read.csv( "cmd_norm.csv")
saihanba <- subset(sub,sid==56969)#筛选出sid为56969的
fwrite(setorder(saihanba, sid, year, month, day), file = "yunnanmengla_tem.csv", quote = T)#保持筛选数据
gc()
library(data.table)
setwd("C:\\Users\\D\\Desktop\\SURF_CLI_CHN_MUL_DAY_V3.0")
rawpath <- "datasets"
rhufiles <- list.files(path = rawpath, full.names = T,pattern = "^SURF_CLI_CHN_MUL_DAY-RHU-13003-.*.TXT")
rhudata <- rbindlist(lapply(rhufiles, fread))[, 1:9]
setnames(rhudata, c("sid", "lat", "long", "elev", "year", "month", "day","rhmean", "rhmin"))
data <- rhudata
fwrite(setorder(data, sid, year, month, day), file = "cmd_raw.csv", quote = T)
data <- fread("cmd_raw.csv")
data[rhmean == 32766, rhmean := NA]
data[rhmin == 32766, rhmin := NA]
data[rhmin >= 300, rhmin := rhmin - 300]
data[, c("rhmean", "rhmin") := list