Dear,

This is a very efficient way. I have checked some values and it is what is
was looking for.

I want to find the days called dry-weather days. It depends but in my case
it is a dry day if on this day the precipitation "N" is equal or less than
0.3 mm and if on the day before the day with N <= 0.3 mm the precipitation
is also equal or less than 0.3 mm.

With this you can set a periods of rainy and dry weather.

I didn't have time check to other methods but soon I will.

Next I want to take the entire time series from 2010-01-01 unti 2013-12-31.

With your reply I will have two vectors then which I need to combine to
find group into rainy day or dry weather day. I think I am going to us
merge() to put the subset vector back into a original data.frame with all
dates.

At first I want to find the solution by myself. If it won't work I will
post a new question to R-help.

Thanks a lot.

Christoph



2014-04-28 14:27 GMT+02:00 Frede Aakmann Tøgersen <frtog@vestas.com>:

> Hi
>
> Here is a very simple way.
>
>
> mydat <- read.table(text="
> Date    N
> 2010-01-01    0
> 2010-01-02    1.9
> 2010-01-03    0
> 2010-01-04    0
> 2010-01-05    1.6
> 2010-01-06    0
> 2010-01-07    0.3
> 2010-01-08    0
> 2010-01-09    1.1
> 2010-01-10    1.7
> 2010-01-11    2.6
> 2010-01-12    0
> 2010-01-13    0
> 2010-01-14    0
> 2010-01-15    0
> 2010-01-16    0
> 2010-01-17    0
> 2010-01-18    0.2
> 2010-01-19    0
> 2010-01-20    0
> 2010-01-21    0
> 2010-01-22    0
> 2010-01-23    0
> 2010-01-24    0
> 2010-01-25    0
> 2010-01-26    0
> 2010-01-27    1.9
> 2010-01-28    6.2
> 2010-01-29    0
> 2010-01-30    0", sep = "", h = TRUE)
>
> mydat$NdayBefore <- c(NA, mydat[-nrow(mydat), "N"])
>
> head(mydat)
>
> subset(mydat, N <= 0.3)
>
> subset(mydat, N <= 0.3 & NdayBefore <= 0.3)
>
> Yours sincerely / Med venlig hilsen
>
>
> Frede Aakmann Tøgersen
> Specialist, M.Sc., Ph.D.
> Plant Performance & Modeling
>
> Technology & Service Solutions
> T +45 9730 5135
> M +45 2547 6050
> frtog@vestas.com
> http://www.vestas.com
>
> Company reg. name: Vestas Wind Systems A/S
> This e-mail is subject to our e-mail disclaimer statement.
> Please refer to www.vestas.com/legal/notice
> If you have received this e-mail in error please contact the sender.
>
>
> > -----Original Message-----
> > From: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org]
> > On Behalf Of Christoph Schlächter
> > Sent: 28. april 2014 10:38
> > To: r-help@r-project.org
> > Subject: [R] subset of obersevation depending on multiple conditions
> >
> > Hello,
> >
> > I want to subset a data.frame containing the variables "Date" in (%Y %m
> %d
> > ) and "N".
> >
> > I want to print "Date" and "N" if  N is less than or equal to 0.3 and if
> > "N" is also less than or equal to 0.3 on the day before the day where "N"
> > is less than or equal to 0.3.
> >
> > This would be the case in line 3 and 4 , 6 and 7, 12 to 18, and so on.
> >
> > "Date"    "N"
> > "1"    2010-01-01    0
> > "2"    2010-01-02    1.9
> > "3"    2010-01-03    0
> > "4"    2010-01-04    0
> > "5"    2010-01-05    1.6
> > "6"    2010-01-06    0
> > "7"    2010-01-07    0.3
> > "8"    2010-01-08    0
> > "9"    2010-01-09    1.1
> > "10"    2010-01-10    1.7
> > "11"    2010-01-11    2.6
> > "12"    2010-01-12    0
> > "13"    2010-01-13    0
> > "14"    2010-01-14    0
> > "15"    2010-01-15    0
> > "16"    2010-01-16    0
> > "17"    2010-01-17    0
> > "18"    2010-01-18    0.2
> > "19"    2010-01-19    0
> > "20"    2010-01-20    0
> > "21"    2010-01-21    0
> > "22"    2010-01-22    0
> > "23"    2010-01-23    0
> > "24"    2010-01-24    0
> > "25"    2010-01-25    0
> > "26"    2010-01-26    0
> > "27"    2010-01-27    1.9
> > "28"    2010-01-28    6.2
> > "29"    2010-01-29    0
> > "30"    2010-01-30    0
> >
> > I tried some methods with subset but I couldn't work it out. Maybe I have
> > to use something like " for (i in x) {} but as a beginner I really don't
> > know how to do it.
> >
> > Can somebody please help me with this.
> >
> > Thanks in advance,
> >
> > Christoph
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

