基本类型

类型初始化

# 整数:L 后缀
number <- 42L

# 双精度数:普通数字
other_number <- 37

# 十六进制字面量和科学计数法
mb <- 0x100000
# mb = 1048576
billion <- 1e9
# billion = 1e+09

# 复数类型
z <- 2 + 3i

# 字符串可以跨行
greeting <- "Hello"
text <- "this is some
multiLine text"

sun_is_star <- TRUE
earth_is_star <- FALSE

# 没有 char 类型:只有长度为 1 的字符串
char_a <- "A"  # 也可写作 "\u0041"

# 向量字面量,以及完全没有值的 NULL
pair <- c(1L, 2L)
nothing <- NULL

cat("number =", number, "\n")
cat("other_number =", other_number, "\n")
cat("mb =", mb, "\n")
cat("billion =", billion, "\n")
cat("z =", z, "\n")
cat("greeting =", greeting, "\n")
cat("text =", text, "\n")
cat("sun_is_star =", sun_is_star, "\n")
cat("earth_is_star =", earth_is_star, "\n")
cat("char_a =", char_a, "\n")
cat("pair =", pair, "\n")
cat("is.null(nothing) =", is.null(nothing), "\n")