要使用小写字母创建矢量,可以使用字母单词,对于大写字母,在R中使用单词LETTERS。如果要使用两种类型的字母创建矢量,则可以使用c函数将这两个单词组合在一起,如果需要创建一个带有随机采样的小写和大写字母值的向量,然后可以使用sample函数。
> x1<-c(LETTERS[1:4],letters[1:4]) > x1
输出结果
[1] "A" "B" "C" "D" "a" "b" "c" "d"
> x2<-c(LETTERS[1:26],letters[1:26]) > x2
输出结果
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" [20] "T" "U" "V" "W" "X" "Y" "Z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" [39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
> x3<-c(LETTERS[1:13],letters[1:13],LETTERS[14:26],letters[14:26]) > x3
输出结果
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "a" "b" "c" "d" "e" "f" [20] "g" "h" "i" "j" "k" "l" "m" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" [39] "Z" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
> x4<-sample(c(LETTERS[1:4],letters[1:4]),100,replace=TRUE) > x4
输出结果
[1] "a" "B" "a" "B" "D" "D" "c" "b" "d" "D" "a" "B" "b" "c" "d" "c" "B" "C" [19] "D" "d" "b" "C" "b" "b" "C" "D" "d" "A" "B" "A" "D" "a" "a" "c" "b" "b" [37] "B" "A" "d" "a" "b" "b" "D" "B" "c" "b" "b" "b" "B" "B" "D" "b" "a" "C" [55] "d" "b" "c" "B" "A" "A" "a" "c" "C" "B" "c" "D" "A" "C" "D" "D" "B" "c" [73] "b" "C" "d" "C" "B" "D" "A" "A" "B" "A" "B" "c" "d" "C" "B" "a" "b" "B" [91] "b" "B" "B" "A" "a" "B" "b" "A" "a" "a"
> x5<-sample(c(LETTERS[1:26],letters[1:26]),120,replace=TRUE) > x5
输出结果
[1] "n" "t" "S" "B" "l" "n" "W" "Z" "a" "k" "X" "P" "E" "V" "Z" "O" "A" "D" [19] "R" "g" "r" "E" "p" "a" "h" "E" "B" "N" "F" "H" "Y" "h" "f" "r" "r" "E" [37] "G" "x" "H" "V" "W" "z" "p" "r" "E" "u" "u" "X" "w" "E" "Q" "G" "k" "N" [55] "f" "P" "S" "o" "p" "w" "C" "g" "T" "p" "D" "T" "f" "N" "j" "z" "d" "v" [73] "D" "a" "L" "J" "B" "g" "T" "y" "a" "L" "G" "E" "Z" "Y" "l" "G" "M" "L" [91] "f" "b" "h" "P" "B" "T" "i" "e" "H" "b" "K" "p" "W" "I" "z" "t" "I" "B" [109] "Q" "T" "z" "e" "n" "q" "m" "I" "n" "g" "r" "B"
> x6<-sample(c(LETTERS[21:26],letters[21:26]),120,replace=TRUE) > x6
输出结果
[1] "X" "Z" "Z" "u" "W" "x" "w" "z" "y" "Z" "u" "Z" "x" "z" "V" "X" "y" "x" [19] "V" "U" "x" "Y" "u" "u" "W" "v" "y" "u" "W" "y" "u" "y" "X" "U" "Y" "u" [37] "v" "Z" "u" "X" "Z" "W" "U" "v" "Z" "W" "W" "X" "y" "Z" "z" "X" "U" "U" [55] "w" "y" "W" "U" "W" "X" "y" "V" "v" "V" "V" "Z" "Y" "v" "u" "y" "z" "W" [73] "U" "V" "U" "u" "v" "U" "Z" "Z" "X" "w" "Z" "u" "w" "Y" "X" "y" "Z" "V" [91] "x" "y" "x" "Y" "y" "v" "z" "u" "Y" "z" "W" "v" "u" "u" "V" "v" "Y" "x" [109] "Z" "y" "z" "w" "z" "u" "x" "x" "Z" "V" "x" "U"
> x7<-sample(c(LETTERS[1:13],letters[1:13]),120,replace=TRUE) > x7
输出结果
[1] "m" "i" "I" "j" "F" "F" "J" "E" "a" "f" "m" "f" "L" "I" "k" "E" "H" "B" [19] "b" "H" "b" "E" "i" "F" "i" "C" "l" "J" "c" "C" "c" "D" "m" "E" "j" "C" [37] "j" "E" "l" "I" "L" "C" "B" "L" "l" "d" "g" "K" "j" "D" "i" "C" "i" "G" [55] "I" "e" "E" "C" "j" "k" "k" "D" "J" "g" "K" "e" "j" "D" "B" "B" "f" "k" [73] "B" "f" "g" "l" "E" "h" "g" "j" "b" "J" "c" "C" "j" "f" "M" "e" "I" "j" [91] "A" "B" "m" "a" "I" "M" "G" "e" "i" "e" "l" "h" "I" "E" "M" "d" "k" "B" [109] "G" "j" "C" "g" "B" "F" "m" "M" "H" "L" "a" "m"
> x8<-sample(c(LETTERS[24:26],letters[24:26]),120,replace=TRUE) > x8
输出结果
[1] "X" "z" "X" "x" "x" "Y" "y" "Z" "x" "z" "Z" "y" "y" "z" "Y" "X" "Y" "X" [19] "Y" "y" "y" "Y" "x" "Y" "Y" "x" "X" "x" "x" "Z" "Y" "z" "x" "X" "x" "z" [37] "z" "Y" "y" "X" "y" "z" "Z" "z" "Z" "x" "Y" "Z" "x" "z" "x" "x" "X" "z" [55] "y" "x" "y" "x" "Z" "x" "Y" "z" "z" "X" "z" "Y" "X" "X" "x" "z" "z" "y" [73] "Z" "z" "Z" "Y" "x" "Y" "x" "Z" "Y" "y" "X" "x" "z" "x" "Z" "x" "z" "y" [91] "Z" "x" "X" "Y" "X" "X" "y" "x" "Y" "z" "z" "X" "Y" "X" "y" "x" "Y" "y" [109] "Y" "X" "z" "Z" "Z" "X" "Y" "Z" "Y" "Z" "X" "Y"