dataframe - R remove row that are not duplicated from a data frame -


i have data looks like:

> data<-data.frame(x=c(1,1,2,3,4,2,2), y=c(1,2,3,4,5,6,8))   x y 1 1 1 2 1 2 3 2 3 4 3 4 5 4 5 6 2 6 7 2 8 

i'm using duplicate in next way:

data[duplicated(data[,1]), ] 

and i'm getting:

  x y 2 1 2 6 2 6 7 2 8 

i like:

  x y 1 1 1     2 1 2 3 2 3 6 2 6 7 2 8 

if value duplicated m times in vector, first incidence not marked duplicate duplicated , subsequent m-1 values marked duplicates. m duplicates, use duplicated(...) | duplicated(..., fromlast=true):

data[duplicated(data[,1]) | duplicated(data[,1], fromlast=true),] #   x y # 1 1 1 # 2 1 2 # 3 2 3 # 6 2 6 # 7 2 8 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -