2

我有一个这样的列表:

> ascii
  [1] "\033" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
 [11] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
 [21] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
 [31] "\032" "\032" "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
 [41] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
 [51] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
 [61] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
 [71] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
 [81] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
 [91] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
[101] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
[111] "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"    "0"   
[121] "0"    "0"    "0"    "0"    "0"    "0"    "\032" "\032" "\032" "\032"
[131] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[141] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[151] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[161] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[171] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[181] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[191] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[201] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[211] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[221] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[231] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[241] "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032" "\032"
[251] "\032" "\032" "\032" "\032" "\032" "\032"

我想在此列表中写入特定的 ascii 字符(此列表称为 ascii)。例如,我想要一个空格“”,您可以在其中看到“\032”。为此,我这样做: ascii[1:32] <- "\032"... 但这会将 "\032" 准确写入这些位置...带有一些字符,例如 "\045" 它可以工作.. .

不要说我请做 ascii[1:32] <- " ",因为我想在列表中介绍其他 ascii 字符,而且我写数字比写字符更好...

非常感谢!

4

1 回答 1

1

编辑:更新

R 只使用数字。所以例如

myascii<-c(65,66,67)

rawToChar(as.raw(myascii))

给ABC

所以你所要做的就是在修改数组时使用 66 而不是 "\066"

于 2013-10-25T17:23:04.530 回答