我有一个长度为 n 的数字字符串向量,如下所示(在本例中,n=3):
[1] "111" "111" "111" "111" "111" "111" "111" "111" "111" "111" "111" "111"
[13] "111" "111" "111" "111" "111" "111" "111" "111" "111" "111" "111" "111"
[25] "111" "111" "111" "111" "111" "111" "111" "1 1" "111" " 1" "111" "112"
[37] "121" "111" "111" "111" "11 " "111" " " "111" "111" "221" "111" "111"
[49] " " "111" "111"
我想将其转换为如下所示的矩阵(或数据框):
V1 V2 V3
1 1 1
1 1 1
1 1 1
...
1 NA 1
1 1 1
NA NA 1
等等
我知道我可以在带有 substring() 和 as.numeric() 的双重嵌套循环中做到这一点,但必须有一种更像 R 的方式来完成这一点。任何人都可以提供线索吗?
TIA。