【发布时间】:2021-06-03 12:43:20
【问题描述】:
我为您准备了以下测试代码:
####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
由reprex package (v2.0.0) 于 2021 年 6 月 3 日创建
现在我想!!!用字符串“DUPLICATE”替换 soundexmatrix1 中的所有重复项,以便矩阵的维度保持不变,并且可以立即看到所有重复项。
任何想法如何做到这一点? 感谢您的帮助!
【问题讨论】:
标签: r matrix duplicates stringdist