0

I want to search in the column "Position" for duplicates and want remove the entire row.

this my data frame dfZ1

    structure(list(Position = c("01.0401  Z", "02.0714A  Z", "02.0715D  Z", 
"02.0715E  Z", "10.1805T  Z", "10.1805V  Z", "10.1808I  Z", "35.9008A  Z", 
"98.0408A  Z", "01.0401 Z", "02.0715D Z", "02.0714A Z", "99.0408A Z", 
"35.9008A Z"), Stichwort = c("Grundlegende Charakt. gem. DVO", 
"Bestandspläne Kanal LP und LS", "Aufp. für koord. Aufnahme und Einb. in GIS", 
"Bestandspläne Stauraumkanal", "GF-UP-Kanalrohr, PN1, DN 1800, SN 10, gew. lief.u.verl.", 
"GF-UP Abschlusskappe, PN1, DN1800, SN10  lief.u.verl.", "Aufz.angef.GF-UP Schacht.DN 1000 auf DN 1800", 
"Abflussregler 10-30 l/s", "Schrämmhammer mit Schlauch", "DVO reg", 
"GIS", "LS", "Neu", "Regler"), Einheit = c("Stk", "m", "PA", 
"PA", "m", "Stk", "Stk", "Stk", "h", "stk", "m²", "VE", "VE", 
"Stk")), row.names = c(NA, 14L), class = "data.frame")

I already tried (and a lot of other things):

dfZ1[!duplicated(dfZ1[c("Position")]),]

but i didn't work.

Any ideas?

THX

Klini
  • 13
  • 4

1 Answers1

0

Dplyr has a function for this, called 'distinct'.

library(dplyr)
df <- as_tibble(dfZ1)
distinct(df, Position)

Edit: to keep all columns, use the parameter .keep_all = TRUE

library(dplyr)
df <- as_tibble(dfZ1)
distinct(df, Position, .keep_all = TRUE)
HarmenD
  • 56
  • 7
  • sorry that does not work, it is deleting all of my other columns – Klini Mar 09 '20 at 10:25
  • You can use .keep_all argument, see edit above. Check here for full documentation: https://dplyr.tidyverse.org/reference/distinct.html – HarmenD Mar 09 '20 at 12:33