Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: remove rows with same in all columns

Tags:

r

row

Input file:

y <- read.table(textConnection('
   c1   c2   c3
1  a    b    -1
2  a    b    -1
3  a    c    1
4  a    b    1
5  a    b    -1
'), header=TRUE)

thus, y is

  c1 c2 c3
1  a  b -1
2  a  b -1
3  a  c  1
4  a  b  1
5  a  b  -1

the output file would be:

  c1 c2 c3
1  a  b -1
3  a  c  1
4  a  b  1

How to remove multiple or duplicate rows with same entry in all columns?

like image 825
Catherine Avatar asked Jan 26 '26 22:01

Catherine


2 Answers

Try unique(y)

> unique(y)
  c1 c2 c3
1  a  b -1
3  a  c  1
4  a  b  1
like image 83
Chase Avatar answered Jan 29 '26 12:01

Chase


?unique. Watch out for floating point variables though...

like image 42
Nick Sabbe Avatar answered Jan 29 '26 12:01

Nick Sabbe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!