[R] (no subject)

David Winsemius dwinsemius at comcast.net
Tue Feb 11 20:28:54 CET 2014


On Feb 11, 2014, at 5:26 AM, Val wrote:

> Hi all,
> I have a sample of data  set with variables day, ID,var and month:
> day ID var  Month
>  1 11  x March
>  1 11  x March
>  1 11  x April
>  1 11  y March
>  1 11  x March
>  1 11  y March
>  2 11  x March
>  2 11  y March
>  3 11  x March
>  3 11  y March
>  4 11  y March
> 
> In the above data set there are four unique days within ID. For example
> ID "11" has four records  on day 1 and if this ID has "y" in "March" then I
> want keep "y"  and discard "xs". Is it possible to keep them in two data
> sets ( wanted and unwanted)
> The output for wanted data set will be:
> 
> 1 11 y March
> 1 11 x April
> 1 11 y March
> 2 11 y March
> 3 11 y March
> 4 11 y March
> thanks in advance

Perhaps:

wanted <- dat[!duplicated(dat), ]
unwanted <- dat[duplicated(dat), ]

?duplicated

-- 
David.

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list