您的位置:首页 > 其它

R语言字母向量

2015-10-25 06:27 281 查看
R中的常量包含以下几种

LETTERS
: the 26 upper-case letters of the Roman alphabet;

letters
: the 26 lower-case letters of the Roman alphabet;

month.abb
: the three-letter abbreviations for the English month names;

month.name
: the English names for the months of the year;

pi
: the ratio of the circumference of a circle to its diameter.

seq()函数
  生成数字向量常用的函数,可定义生成向量的最大最小值,from = min, to = max;用 by = ***可定义步长,默认为1。length.out定义向量所包含的数字个数。

想要生成字符向量,先生成数字,然后把数字转化为字母
> e <- LETTERS[seq(1,26)]
> e
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"


R语言中向量是从1开始
> e[1]
[1] "A"


给e向量添加元素
> e[27] <- "AA"
> e
[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"  "AA"


获取e中某几个元素
> e[c(5,8,13)]
[1] "E" "H" "M"


获取e中连续的几个元素
> e[5:16]
[1] "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: