如何用随机字母对r中的短语进行编码

时间:2019-02-02 18:12:30

标签: r encoding gsub

我想用存储在矩阵中的采样字母替换短语“ hellothere”。我希望用相反行中的字母代替短语中的字母。结果是h被g替换,e被a替换,l被x替换,依此类推。

我已经使用了gsub()命令,但是我缺乏如何使每个字母替换为相反行字母的知识。

plugboard<-matrix(sample(letters), nrow=2)
######
plugboard
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,] "v"  "y"  "r"  "d"  "n"  "l"  "f"  "t"  "e"  "w"   "u"   "h"   "i"  
[2,] "p"  "o"  "j"  "k"  "b"  "x"  "q"  "s"  "a"  "z"   "c"   "g"   "m"      

0 个答案:

没有答案