-1

Ex:Assume a data frame I/P Name value

A.          10
A.          20
B.          30
B.          40

As per my requirements , O/p:

A.        10
B.        30

Alone and remove other duplicate values of A& B

Vivek Kalyanarangan
  • 8,951
  • 1
  • 23
  • 42
Appu
  • 1

2 Answers2

1

Remove Duplicates -

Based on single column

df[!duplicated(df$V1),]

  V1 V2
1  A 10
3  B 30

Based on all columns

unique(df)

  V1 V2
1  A 10
2  A 20
3  B 30
4  B 40

Based on subset columns

Change the data to review output -

A,10,10
A,20,20
B,30,20
B,40,20

Now let's say we want to filter duplicates based on V1 and V3 -

df[!duplicated(df[ , c(1,3) ]), ]

  V1 V2 V3
1  A 10 10
2  A 20 20
3  B 30 20
Vivek Kalyanarangan
  • 8,951
  • 1
  • 23
  • 42
1

If there multiple rows create separate data frame for A and B then select first row and first column.

 df1[1,1]

 df2[1,1]
learner
  • 43
  • 1
  • 6
Zeeshan
  • 1,208
  • 1
  • 14
  • 26