Skip to content

Remove duplicated rows

5 messages · chrisli1223, PIKAL Petr, Gustaf Rydevik +1 more

#
Hi
r-help-bounces at r-project.org napsal dne 23.04.2010 04:05:00:
and
only
Hm. Strange. You want to keep lines 1,3 an 4. for A. What about line 5? 
Why do you want to keep line 1 and 4 which have A an 4 in both columns?

test=read.table("clipboard", header=T)
test[!duplicated(paste(test[,1], test[,3])),]
  Name      Date Value
1    A 1/01/2000     4
3    A 3/01/2000     5
5    A 5/01/2000     1
6    B 6/01/2000     2
7    B 7/01/2000     1

Gives you unique values, however I am not sure if it is what you want.

Regards
Petr
I
http://r.789695.n4.nabble.com/Remove-duplicated-
http://www.R-project.org/posting-guide.html
#
On Fri, Apr 23, 2010 at 4:05 AM, chrisli1223
<chrisli at austwaterenv.com.au> wrote:
Hi,

This code is a bit ugly, but it works. Hope it helps.
/Gustaf

library(zoo)
test<-read.table("clipboard",header=T)
test$code<-paste(test$Name,test$Value,sep="")

drop.ndx<-rollapply(zoo(test$code),3,function(x)(x[2]%in%c(x[1],x[3])))

drop.ndx<-c(FALSE,drop.ndx,FALSE)
test[!drop.ndx,]
#
Try this:

DF[!duplicated(DF[-2]),]


On Thu, Apr 22, 2010 at 10:05 PM, chrisli1223
<chrisli at austwaterenv.com.au> wrote:
3 days later