Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jim Lemon
Hi Ahmet, My apologies, the final for loop should read: for(run in 1:length(sm.rle$lengths)) { if(sm.rle$values[run]) { cat("Day",day_of_year,"-",day_of_year+sm.rle$lengths[run], "-",sm.rle$lengths[run],"days\n") } day_of_year<-day_of_year+sm.rle$lengths[run] } Jim On Fri, Aug 7, 2020 at

Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jim Lemon
Hi Ahmet, Here is a way to get the result you ask for for one geographic grid cell. You may want more detail or something, but this is a "reproducible example". # retrieved from ftp://ftp2.psi.noaa.gov/Datasets/ncep.renalysis.dailyavgs/surface_gauss/soilw.1-10cm.gauss.1949.nc library(ncdf4) soilm<

Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jim Lemon
Hi Ahmet, I think what you are looking for can be done using run length encoding (rle). # make up some data soil_moisture<-sin(seq(0,4*pi,length.out=730))+1.1 dates<-as.Date(as.Date("2018-01-01"):as.Date("2019-12-31"), origin=as.Date("1970-01-01")) # get a logical vector for your condition under.

Re: [R] find number of consecutive days in NC files by R

2020-08-06 Thread Jeff Newmiller
You need to make a small fake dataset that illustrates what you have and what you want out of it. Telling us you are not getting what you want is simply not useful. On August 6, 2020 8:58:09 AM PDT, "ahmet varlı" wrote: >Hi all, > > >There are 365 days of soil moisture NC files and I am trying

[R] find number of consecutive days in NC files by R

2020-08-06 Thread ahmet varlı
Hi all, There are 365 days of soil moisture NC files and I am trying to find out how many days the values are below and above this certain threshold are repeated by R. However, I couldn't reach exactly what I wanted. For example, Daily soil moisture is below 0.3 without interrupting how many d

Re: [R] Print and plot a cross Data

2020-08-06 Thread Pedro páramo
Hi Jim, Many thanks for your help, I will try a 2D plot and then pass to 3D. I am trying something like this: tus.datos<-read.table("datayield.csv",sep=";",header=TRUE) data_types<-c("PY_1Y","PY_2Y","PY_3Y","PY_4Y","PY_5Y","PY_6Y","PY_7Y") row_subset<-tus.datos$DATA_TYPE %in% data_types x<-tu