[R] Subscripting

David Winsemius dwinsemius at comcast.net
Wed Feb 10 20:44:22 CET 2010


On Feb 10, 2010, at 2:26 PM, GL wrote:

>
> Dataframe1 contains a list of specific dates. Dataframe2 contains a  
> large
> dataset, one element of which is Date. How do I create a subset of
> Dataframe2 that excludes the dates from Dataframe1? I know how to do  
> it with
> a left outer join vs null in SQL, but I can't figure out how to do  
> it more
> directly via the subcripts that already exist?
>
> Dateframe1
>
> Date
> 1/1/2010
> 1/18/2010
>
>
> Dataframe2
>
> Date Attribute Count
> 1/1/2010 Red 5
> 1/15/2010 Green 2
> 1/18/2010 Purple 8
> 1/19/2010 Yellow 3
>

Something along the lines of this untested code:

  Dataframe2[ !(Dataframe2$Date %in% Dataframe1$Date) , ]

?"["
?"%in%"


> ResultingDataframe (Dataframe2 minus the rows that have Dates in  
> Dataframe1)
>
> Date Attribute Count
> 1/15/2010 Green 2
> 1/19/2010 Yellow 3
>
> -- 
> View this message in context: http://n4.nabble.com/Subscripting-tp1476330p1476330.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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list