How do I remove duplicates in the "conc" column for each run without using any for loops, making my own function or using any packages?

Viewed 18

I have this database from R called DNase (I've only attached a sample):

Run conc density
1 0.04882812 0.017
1 0.04882812 0.018
1 0.19531250 0.121
1 0.19531250 0.124
1 0.39062500 0.206
1 0.39062500 0.215
1 0.78125000 0.377
1 0.78125000 0.374
1 1.56250000 0.614
1 1.56250000 0.609
1 3.12500000 1.019
1 3.12500000 1.001
1 6.25000000 1.334
1 6.25000000 1.364
1 12.50000000 1.730
1 12.50000000 1.710
2 0.04882812 0.045
2 0.04882812 0.050
2 0.19531250 0.137
2 0.19531250 0.123
2 0.39062500 0.225
2 0.39062500 0.207
2 0.78125000 0.401
2 0.78125000 0.383
2 1.56250000 0.672
2 1.56250000 0.681
2 3.12500000 1.116
2 3.12500000 1.078
2 6.25000000 1.554
2 6.25000000 1.526
2 12.50000000 1.932
2 12.50000000 1.914

I need to remove the duplicates in the conc column for run 1 and 2 without using loops.

I've tried this:

DNase[!duplicated(DNase$conc),]

but I get this:

Run conc density
1 0.04882812 0.017
1 0.19531250 0.121
1 0.39062500 0.206
1 0.78125000 0.377
1 1.56250000 0.614
1 3.12500000 1.019
1 6.25000000 1.334
1 12.50000000 1.730

As you can see, I only get run 1 returned.

I need a way to segregate the runs and then remove duplicates from the conc column. I've tried using apply and also tried splitting the run as a list but nothing seems to work.

Really appreciate some guidance on this. Thanks.

1 Answers

Here another option using dplyr approach:

DNase %>% group_by(Run) %>% distinct(conc, .keep_all = TRUE)
Related