数据类型
R中包含数字、字符、日期、逻辑、因子这几种基本的数据类型。
x <- 1
y <- 2 * x
print(x + y)
## [1] 3
x <- "hello"
y <- "world"
try(print(x + y))
## Error in x + y : 二进列运算符中有非数值参数
字符型如果使用运算符号就会报错。
print(paste(x, y, sep = " "))
## [1] "hello world"
使用paste
可以将2个字符串合并为1个,sep
指定连接符。