0

I have the following Data frame

ID <- c("0141-np66-knw0", "0141-np66-knw0", "02y9-1hhy-0qn8", "06ya-mut5-ps3q","06ya-mut5-ps3q","06ya-mut5-ps3q")
town <- c("Town A","Town A","Town B","Town C", "Town D","Town D")
village <- c("Village F","Village K", "Village W", "Village H", "Village O", "Village Z")
towns <- data.frame(ID, town, village)

              ID   town   village
1 0141-np66-knw0 Town A Village F
2 0141-np66-knw0 Town A Village K
3 02y9-1hhy-0qn8 Town B Village W
4 06ya-mut5-ps3q Town C Village H
5 06ya-mut5-ps3q Town D Village O
6 06ya-mut5-ps3q Town D Village Z

In the end, I want 1 data frame that contains only distinct rows of the column ID

Expected Output

              ID   town   village
1 0141-np66-knw0 Town A Village F
3 02y9-1hhy-0qn8 Town B Village W
4 06ya-mut5-ps3q Town C Village H
andy
  • 1,947
  • 5
  • 27
  • 46
  • do you mean the rest of the rows, not columns? `split(towns, duplicated(towns$ID))` – rawr Oct 05 '20 at 06:13
  • I've edited the question to show the expected output – andy Oct 05 '20 at 06:19
  • `towns %>% distinct(ID, .keep_all = TRUE)` – Ronak Shah Oct 05 '20 at 06:23
  • You're specifically trying to get rid of the rest of those rows (which have unique data in them)? If you don't care about the town and village values, just drop them from your dataset and call `unique` on it. – BrianLang Oct 05 '20 at 10:25

0 Answers0