Hello I am new user of R. I try to creat a df but the lenght here gives me 0 and it should give 366. I don't know why.
# file.exists("D:/Preparation data/weather data/P_D//file_name")
#### Precipitation
# Precipitation directory
setwd("D:/Preparation data/weather data/")
prec_dir <- "D:/Preparation data/weather data/P_D/era5_prec_2020/"
# Check number of days in the year
days_in_year(year)
# Load precipitation for the year
prec_csv_files <- list.files(prec_dir)
prec_all = list()
for (i in 1:length(prec_csv_files)) {
prec <- read.csv(paste0(prec_dir,"prec", year, ".csv"))
}
# Set the key
prec$key <- paste0(gsub( " ", "_", prec$Province), "_", prec$fid)
prec_colnames <- grep("P_", names(prec), value=TRUE)
# Filter by key
prec <- prec[prec$key == key, prec_colnames]
prec_vec <- as.vector(t(prec[, prec_colnames]))
length(prec)
#remove unwanted data
rm(prec_dir,prec)