[18688] in s-news-athena
Re[2]: [S] identical obervations
daemon@ATHENA.MIT.EDU (Jean Adams)
Wed Jul 21 12:24:37 1999
Mime-Version: 1.0
Date: Wed, 21 Jul 1999 12:22:18 -0600
Message-Id: <000F831E.@usgs.gov>
From: Jean_Adams@usgs.gov (Jean Adams)
To: John Thaden <jjthaden@flash.net>
Cc: "Man S. Kwok" <mankwok@phoenix.princeton.edu>, s-news@wubios.wustl.edu
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Description: cc:Mail note part
This will not necessarily work. For example, with data frame D,
below, only rows 3 and 4 are identical. But row 7 contains duplicate
column observations, and so is excluded by John Thaden's approach.
D <- data.frame(x1=c(2, 2, 2, 2, 3, 3, 3),
x2=c("a", "a", "b", "b", "b", "c", "c"),
x3=c(10, 15, 20, 20, 30, 10, 15))
D
x1 x2 x3
1 2 a 10
2 2 a 15
3 2 b 20
4 2 b 20
5 3 b 30
6 3 c 10
7 3 c 15
D[!(duplicated(D$x1) & duplicated(D$x2) & duplicated(D$x3)), ]
x1 x2 x3
1 2 a 10
2 2 a 15
3 2 b 20
5 3 b 30
6 3 c 10
Instead, something like this should work.
D[!duplicated(apply(D, 1, paste, collapse="-")), ]
x1 x2 x3
1 2 a 10
2 2 a 15
3 2 b 20
5 3 b 30
6 3 c 10
7 3 c 15
JVA
Jean V. Adams USGS Biological Resources Division
e-mail: jean_adams@usgs.gov Great Lakes Science Center
phone: (734) 214-9307 1451 Green Road
FAX: 734-994-8780 Ann Arbor, MI 48105-2899 USA
______________________________ Reply Separator _________________________________
Subject: Re: [S] identical obervations
Author: John Thaden <jjthaden@flash.net> at NBS-Internet-Gateway
Date: 7/21/99 10:29 AM
: I have a data set of 6 varaibles and 2000 observations. I need to remove
: repeated observations. Is there a quick way to locate exactly indentical
: observations in S, without resorting to looping? Thanks in advance.
> D <- D[!(duplicated(D$x1) & duplicated(D$x2) & duplicated(D$x3)
+ & duplicated(D$x4) & duplicated(D$x5) & duplicated(D$x6)), ]
John Thaden
Little Rock, Arkansas, USA
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news