[R] filtering signals per day

Peter Alspach Peter.Alspach at plantandfood.co.nz
Wed Mar 3 20:53:44 CET 2010


Tena koe Anna

The following appears to do what you want (anna is a dataframe
containing the data you provided):

anna$Test <- anna$Signals
anna[duplicated(paste(anna$Dates, anna$Signals)),'Test'] <- 0
anna
      Dates Signals Filtered.Signal Test
1  02-11-06       0               0    0
2  02-11-06       1               1    1
3  02-11-06       0               0    0
4  02-11-06       1               0    0
5  02-11-06       1               0    0
6  02-11-06       0               0    0
7  03-11-06       1               1    1
8  03-11-06       1               0    0
9  03-11-06       0               0    0
10 03-11-06       1               0    0
11 03-11-06       0               0    0

HTH ....

Peter Alspach

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of anna
> Sent: Thursday, 4 March 2010 8:20 a.m.
> To: r-help at r-project.org
> Subject: [R] filtering signals per day
> 
> 
> Hello R lovers,
> I have a vector of dates and signals. I want to filter the 
> signals per day in a way that only the first signal of the 
> day remains like this:
> Dates               Signals       Filtered Signal
> 2006-11-02         0                    0
> 2006-11-02         1                    1
> 2006-11-02         0                    0 
> 2006-11-02         1                    0
> 2006-11-02         1                    0 
> 2006-11-02         0                    0
> 2006-11-03         1                    1
> 2006-11-03         1                    0 
> 2006-11-03         0                    0
> 2006-11-03         1                    0
> 2006-11-03         0                    0
> 
> The thing is that I want to do it with matrix functions and 
> not doing a loop but I still have no clue even after having 
> spent time on it. Can somebody please help me? thank you!
> 
> 
> 
> -----
> Anna Lippel
> --
> View this message in context: 
> http://n4.nabble.com/filtering-signals-per-day-tp1577044p1577044.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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