Replace duplicates in matrix

Hello,
i have the following test-code for you:

####TESTING HERE
test = tibble::tribble(
                          ~Name1,           ~Name2,          ~Name3,
                   "Paul Walker",    "Paule Walkr",   "Heiko Knaup",
                "Ferdinand Bass", "Ferdinand Base", "Michael Herre"
                )

library(stringdist)
output <- list()
for (row in 1:nrow(test)) 
{
  codephon = phonetic(test[row,], method = c("soundex"), useBytes = FALSE)
  output[[row]] <- codephon
}

#building the matrix with soundex input
phoneticmatrix = matrix(output)
soundexspalten=str_split_fixed(phoneticmatrix, ",", 3)
#> Error in str_split_fixed(phoneticmatrix, ",", 3): konnte Funktion "str_split_fixed" nicht finden
soundexmatrix0 = gsub('[()c"]', '', soundexspalten)
#> Error in gsub("[()c\"]", "", soundexspalten): Objekt 'soundexspalten' nicht gefunden
soundexmatrix1 = gsub("0000", "", soundexmatrix0)
#> Error in gsub("0000", "", soundexmatrix0): Objekt 'soundexmatrix0' nicht gefunden

Created on 2021-06-03 by the reprex package (v2.0.0)

now I want to !!!replace all duplicates in soundexmatrix1 with the string "DUPLICATE" so the dimension of the Matrix stays the same and all duplicates can be seen straight away.

Any ideas how to do that?
Thanks for your help!

is the immediate problem. See if you can work with

####TESTING HERE
test = tibble::tribble(
  ~Name1,           ~Name2,          ~Name3,
  "Paul Walker",    "Paule Walkr",   "Heiko Knaup",
  "Ferdinand Bass", "Ferdinand Base", "Michael Herre"
)

library(stringdist)
library(stringr)
output <- list()
for (row in 1:nrow(test)) 
{
  codephon = phonetic(test[row,], method = c("soundex"), useBytes = FALSE)
  output[[row]] <- codephon
}

#building the matrix with soundex input
phoneticmatrix = matrix(output)
soundexspalten=str_split_fixed(phoneticmatrix, ",", 3)
#> Warning in stri_split_regex(string, pattern, n = n, simplify = simplify, :
#> argument is not an atomic vector; coercing

soundexmatrix0 = gsub('[()c"]', '', soundexspalten)

soundexmatrix1 = gsub("0000", "", soundexmatrix0)

soundexmatrix1
#>      [,1]   [,2]    [,3]   
#> [1,] "P442" " P442" " H225"
#> [2,] "F635" " F635" " M246"

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.