0

I have a table which contains multiple rows of the different data for a key of multiple columns.

Table looks like this:

    A    B    C
1   1    1    2
2   1    1    3 
3   2    1    4
4   1    2    4
5   2    2    3
6   2    3    1
7   2    3    2
8   2    3    2

I also discovered how to remove all of the duplicate elements using unique command for multiple colums, so the data duplication is not a problem.

I would like to know how to for every key(columns A and B in example) in the table to find only the minimum value in third column(C column in table)

At the end table should look like this

    A    B    C
1   1    1    2 
3   2    1    4
4   1    2    4
5   2    2    3
6   2    3    1

Thanks for any help. It is really appreciated

In any question, feel free to ask

depecheSoul
  • 896
  • 1
  • 12
  • 29

1 Answers1

0
con <- textConnection("    A    B    C
1   1    1    2
2   1    1    3 
3   2    1    4
4   1    2    4
5   2    2    3
6   2    3    1
7   2    3    2
8   2    3    2")

df <- read.table(con, header = T)
df[with(df, order(A, B, C)), ]

df[!duplicated(df[1:2]),]
#   A B C
# 1 1 1 2
# 3 2 1 4
# 4 1 2 4
# 5 2 2 3
# 6 2 3 1