在R中创建向量有四个主要限制。在创建任何类型的向量时,我们必须记住这些限制-
向量名称不能带有%符号。
向量名称不能以数字开头。
向量可以以点开头,但后面不能有数字。
向量不能以下划线开头。
带%符号的向量-
x1%<-1:20 Error: unexpected input in "x1%<-1:20" x1%first<-1:20 Error: unexpected input in "x1%first<-1:20" %x1<-1:20 Error: unexpected input in "%x1<-1:20" x1_%_first<-1:20 Error: unexpected input in "x1_%_first<-1:20" x1first_1_%<-1:20 Error: unexpected input in "x1first_1_%<-1:20" x1first__%<-1:20 Error: unexpected input in "x1first__%<-1:20"
以数字开头的向量-
1x<-1:20 Error: unexpected symbol in "1x" 1_x<-1:20 Error: unexpected input in "1_" 101_x<-1:20 Error: unexpected input in "101_" 123_x<-1:20 Error: unexpected input in "123_" 1number_x<-1:20 Error: unexpected symbol in "1number_x" 1number<-1:20 Error: unexpected symbol in "1number"
以点开头的向量-
.x1<-1:10 .x1 [1] 1 2 3 4 5 6 7 8 9 10 .1x<-1:10 Error: unexpected symbol in ".1x" .1_x<-1:10 Error: unexpected input in ".1_" .100_x<-1:10 Error: unexpected input in ".100_" .1of_x<-1:10 Error: unexpected symbol in ".1of_x" .2of_x<-1:10 Error: unexpected symbol in ".2of_x" .1ofx<-1:10 Error: unexpected symbol in ".1ofx"
以下划线开头的向量-
_x1<-1:10 Error: unexpected input in "_" _first<-1:10 Error: unexpected input in "_" _first_variable<-1:10 Error: unexpected input in "_" _variable1<-1:10 Error: unexpected input in "_" _firstvariable<-1:10 Error: unexpected input in "_" _V1<-1:10 Error: unexpected input in "_" _1_var <-1:10 Error: unexpected input in "_"