need help in reading .nc4 files in folder inside a loop

Viewed 20

I'm new to R so excuse for this trivial question. I'm currently designing a loop to read .nc4 extension files that I have stored inside a folder and to extract variables from it inside a single database. currently testing time only.

    Gpm= list.files("Filepath",pattern='*.nc4',full.names=TRUE)
for(i in seq_along(Gpm)) {
  print(i)
  p<-nc_open(Gpm[i])
  print(p)
 t<-ncvar_get(p,"time")
 ln<-ncvar_get(p,"lon")
 lt<-ncvar_get(p,"lat")
 rtime<-as.Date(t,origin='1970-01-01')
 df<-rbind(rtime)
}

Ofcourse its not working. i does goes from 1-4 (I'm doing a trial run for 4 files before moving to 366), but the nc variables dont. any suggestions?

1 Answers

Modify the last line to be df <- rbind(df, rtime)

Related