Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要以一种非常具体的方式匿名化名称,以便整个字符串的格式仍然相同(保留空格、连字符、句点),但所有字母都被打乱了。我想始终如一地将所有 A 替换为 C,将所有 D 替换为 Z,依此类推。我该怎么做?
我们可以用chartr
chartr
chartr('AD', 'CZ', str1) #[1] "CZ,ZC. C"
str1 <- c('AD,DA. C')
也许使用gsub?
gsub
string <- "ABCDEFG" text <- gsub('A', 'C', string ) string <- gsub('D', 'Z', string ) string [1] "CBCZEFG"