[R] subset of obersevation depending on multiple conditions
Ivan Calandra
ivan.calandra at univ-fcomte.fr
Mon Apr 28 12:39:34 CEST 2014
Hi Christoph,
I'm not sure I understand your conditions. It is an "AND" or an "OR",
i.e. must both conditions be met to subset or any one of them?
From your explanation, I would think you really mean AND, but then I
don't understand why you would select both lines 3 and 4.
I would just say:
df[df$N <= 0.3, ]
but I might be missing something.
You should also be careful with floating point numbers, I guess.
HTH,
Ivan
--
Ivan Calandra
University of Franche-Comté
Laboratoire Chrono-Environnement
Bureau ATER -107L
16, Route de Gray
25030 Besançon Cedex, France
ivan.calandra at univ-fcomte.fr
+33 (0) 381 66 20 60
http://chrono-environnement.univ-fcomte.fr/spip.php?article1830
Le 28/04/14 10:37, Christoph Schlächter a écrit :
> 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 at 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.
>
More information about the R-help
mailing list