Try this: f$Filtered <- unlist(sapply(unstack(f, Signals ~ Dates),
function(.x)tabulate(which(as.logical(.x))[1], length(.x)))) On Wed, Mar 3, 2010 at 4:20 PM, anna <lippelann...@hotmail.com> wrote: > > 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@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ 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.