赋值运算符
R 语言变量可以使用向左,向右或等于操作符来赋值。
下表列出了 R 语言支持的赋值运算符。
运算符 |
描述 |
<− = <<− |
向左赋值。 |
<− = <<− |
向右赋值。 |
实例
# 向左赋值
v1 <- c(3,1,TRUE,"jsrun")
v2 <<- c(3,1,TRUE,"jsrun")
v3 = c(3,1,TRUE,"jsrun")
print(v1)
print(v2)
print(v3)
# 向右赋值
c(3,1,TRUE,"jsrun") -> v1
c(3,1,TRUE,"jsrun") ->> v2
print(v1)
print(v2)
执行以上代码输出结果为:
[1] "3" "1" "TRUE" "jsrun"
[1] "3" "1" "TRUE" "jsrun"
[1] "3" "1" "TRUE" "jsrun"
[1] "3" "1" "TRUE" "jsrun"
[1] "3" "1" "TRUE" "jsrun"