R有许多内置常量。以下常量可用:
LETTERS:罗马字母的26个大写字母
letters:罗马字母的26个小写字母
month.abb:英文月份名称的三个字母的缩写
month.name:一年中月份的英文名称
pi:圆的周长与其直径之比
根据字母和月份常量,可以创建向量。
1)字母顺序:
> letters [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" > LETTERS[7:9] [1] "G" "H" "I" > letters[c(1,5,3,2,4)] [1] "a" "e" "c" "b" "d"
2)月缩写或月名称的顺序:
> month.abb [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec" > month.name[1:4] [1] "January" "February" "March" "April" > month.abb[c(3,6,9,12)] [1] "Mar" "Jun" "Sep" "Dec"