说明 | R | Python |
赋值运算符 |
v1 <- c(3,1,TRUE,2+3i) v2 <<- c(3,1,TRUE,2+3i) v3 = c(3,1,TRUE,2+3i) print(v1) print(v2) print(v3) |
= |
冒号运算符。 它为向量按顺序创建一系列数字。 |
v <- 2:8 print(v) |
v = range(2, 8) |
此运算符用于标识元素是否属于向量。 |
v1 <- 8 v2 <- 12 t <- 1:10 print(v1 %in% t) print(v2 %in% t) |
v1 in list1 |
if 语句 |
x <- 30L if(is.integer(x)) { print("X is an Integer") } |
|
if...else 语句 |
x <- c("what","is","truth") if("Truth" %in% x) { print("Truth is found") } else { print("Truth is not found") } |
|
for 循环 |
v <- LETTERS[1:4] for ( i in v) { print(i) } |
|