1

everyone I am just a beginner of R,so following code or question might misunderstand R function. Hopes you guys don't mind it.

  1. I got hundreds ERA Interim Daily Precipitation data from ECMWF.

  2. Each monthly NetCDF file contain twice per day precipitation and extract them by Longitude & Latitude.

  3. Finally convert to CSV file,but itself store (12:00 ;00:00) two columns for same days rainfall.

Image of output CSV

Ideally ,I would like to obtain single day rainfall for whole year or month. But, don't know how to do it in R.

  • Q1: Is there any library or function support merge columns names and keep same dates?

  • Q2: However, I am not sure lubridate library can accomplish or others will be better.

-----Thanks for any answers---------

If somebody want to view NetCDF file and .csv file ,you can get from my google driver: https://drive.google.com/drive/folders/1ogQp_-MlvmJCDmzm38dXHbUmWAM6hi1v?usp=sharing P.S In Google Drive SumMonth.csv is extract result

R Code:

library(raster)
library(ncdf4)
f <- list.files("C:/Users/asus/Downloads/extract",
                pattern = "*.nc", full.names = TRUE)
ncloop <-lapply(f,nc_open)# Read whold folder nc.file

brick <-lapply(f,brick,varname = "tp")

brick2 <-stack(brick)# Combine all month

dim(brick2)#check dim right

##### input location file with Lon&Lat

pointCoordinates <- read.table("C:/Users/asus/Downloads/pointFile.csv",

header = TRUE, sep = ",",stringsAsFactors=FALSE)

coordinates(pointCoordinates) <- ~Long + Lat # Assign XY for extract

rasValue=extract(brick2, pointCoordinates)#extract

combinePointValue=cbind(pointCoordinates,rasValue)#construct database 

## Outout as csv
cc <- as.data.frame(combinePointValue)

write.csv(cc,file ="SumMonth.csv")
lbusett
  • 5,801
  • 2
  • 24
  • 47
tanner
  • 11
  • 3
  • 2
    Welcome to SO. Please consider that users are often unwilling of downloading data from unknown sources. To facilitate users helping you, it would be better to share a minimal part of your data within the question. In this case, you could share the results of dput(head(cc[,1:10])) (see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – lbusett Jan 02 '19 at 21:24

0 Answers0