An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090312/b5143832/attachment-0002.pl>
Removing
5 messages · Tammy Ma, Patrick Burns, David Winsemius
Much simpler would be:
act2[!duplicated(act2$Rep),] #use the negation of the duplicated
function on $Rep and indexing
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
Cannot reproduce the blank line though.
David Winsemius
On Mar 12, 2009, at 5:02 AM, Tammy Ma wrote:
>
> Hi All,
>
>
>> act_2
> Date Dtime Hour Min Second Rep
> 51 2006-02-22 14:52:18 14 52 18 useractivity_act
> 52 2006-02-22 14:52:18 14 52 18 4
> 55 2006-02-22 14:52:49 14 52 49 4
> 57 2006-02-22 14:52:51 14 52 51 4
> 58 2006-02-22 14:52:52 14 52 52 3
> 60 2006-02-22 14:54:42 14 54 42 useractivity_idle
>
> I want to change act_2 to
> Date Dtime Hour Min Second Rep
>
> 51 2006-02-22 14:52:18 14 52 18 useractivity_act
>
> 52 2006-02-22 14:52:18 14 52 18 4
> 58 2006-02-22 14:52:52 14 52 52 3
> 60 2006-02-22 14:54:42 14 54 42 useractivity_idle
>
> in other word, I want to keep 1st if there are many repeated value,
> I made the program as:
>
>
> rm_r<-function(act_2){
> dm<-dim(act_2)[1]-1
> for(i in 2:dm){
>
> if(act_2$Rep[j]==act_2$Rep[i]){
> act_2<-act_2[-j,]
> }else{
> act_2<-act_2
> }
> }
> return(act_2)
> }
>
> But it only remove one row..whats the problem? How should i modify
> it? Thanks alot.
>
> Tammy
>
>
> _________________________________________________________________
> Invite your mail contacts to join your friends list with Windows
> Live Spaces. It's easy!
> http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
> [[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
Heritage Laboratories
West Hartford, CT
Simpler, but maybe wrong. Not duplicated was my first response as well, but then I began wondering if the question implied globally duplicated or duplicated within subgroups. Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User")
David Winsemius wrote:
Much simpler would be:
act2[!duplicated(act2$Rep),] #use the negation of the duplicated
function on $Rep and indexing
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
Cannot reproduce the blank line though.
True, I suppose. The specification from Ma could have been more
explicit. Should she want to only have duplicates in sequence, then
perhaps the use of construction within the rle function would be useful.
act2[ act2$Rep[-1] != act2$Rep[-length(act2$Rep)], ]
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
57 2006-02-22 14:52:51 14 52 51 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
Which turns out on examination to be isomorphic to Gabor's earlier
efforts.
David Winsemius On Mar 12, 2009, at 2:31 PM, Patrick Burns wrote: > Simpler, but maybe wrong. Not duplicated > was my first response as well, but then I began > wondering if the question implied globally > duplicated or duplicated within subgroups. > > > Patrick Burns > patrick at burns-stat.com > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of "The R Inferno" and "A Guide for the Unwilling S User") > > David Winsemius wrote: >> Much simpler would be: >> >> act2[!duplicated(act2$Rep),] #use the negation of the duplicated >> function on $Rep and indexing >> >> Date Dtime Hour Min Second Rep >> 51 2006-02-22 14:52:18 14 52 18 useractivity_act >> 52 2006-02-22 14:52:18 14 52 18 4 >> 58 2006-02-22 14:52:52 14 52 52 3 >> 60 2006-02-22 14:54:42 14 54 42 useractivity_idle >> >> Cannot reproduce the blank line though. David Winsemius, MD Heritage Laboratories West Hartford, CT
On Mar 12, 2009, at 3:02 PM, David Winsemius wrote:
True, I suppose. The specification from Ma could have been more
explicit. Should she want to only have duplicates in sequence, then
perhaps the use of construction within the rle function would be
useful.
act2[ act2$Rep[-1] != act2$Rep[-length(act2$Rep)], ]
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
57 2006-02-22 14:52:51 14 52 51 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
Which turns out on examination to be isomorphic to Gabor's earlier
efforts.
Almost ... but not quite. The addition of a TRUE to that logical vecor (as in Bill Dunap's posting as well as Gabor's solution) is needed to keep this from failing in some instances, although this test case did not expose the flaw. act2[c(TRUE, act2$Rep[-1] != act2$Rep[-length(act2$Rep)]), ]
-- David Winsemius On Mar 12, 2009, at 2:31 PM, Patrick Burns wrote:
Simpler, but maybe wrong. Not duplicated was my first response as well, but then I began wondering if the question implied globally duplicated or duplicated within subgroups. Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User") David Winsemius wrote:
Much simpler would be:
act2[!duplicated(act2$Rep),] #use the negation of the duplicated
function on $Rep and indexing
Date Dtime Hour Min Second Rep
51 2006-02-22 14:52:18 14 52 18 useractivity_act
52 2006-02-22 14:52:18 14 52 18 4
58 2006-02-22 14:52:52 14 52 52 3
60 2006-02-22 14:54:42 14 54 42 useractivity_idle
Cannot reproduce the blank line though.
David Winsemius, MD Heritage Laboratories West Hartford, CT
______________________________________________ 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