[R] filtering rows

David Winsemius dwinsemius at comcast.net
Tue Oct 11 18:56:28 CEST 2011


On Oct 11, 2011, at 11:18 AM, Samir Benzerfa wrote:

> Hi everyone,
>
>
>
> I've got two data sets as below. My question now is: how can I use  
> Dataset2
> as a filter for Dataset1? My goal is just to keep the rows of  
> Dataset1 where
> the first column (Date) matches the Dates in Dataset2.
>

Perhaps:

merge(Dataset1, Dataset2)

Or:

Dataset1[ Dataset1$Date %in% Dataset1$Date , ]

-- 
David.
>
> I would appreciate any solutions to this issue.
>
>
>
> Many thanks!
>
> S.B.
>
>
>
> Dataset1:
>
>                Date      A               B             C             D
>
> 1             1977      10           11           12           13
>
> 2             1978      14           15           16           17
>
> 3             1979      18           19           20           21
>
> 4             1980      22           23           24           25
>
> 5             1981      26           27           28           29
>
>
>
> Dateset2:
>
>
>
>                Date
>
> 1             1977
>
> 2             1978
>
> 3             1979
>
>
>
>
> 	[[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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list