向量赋值
x <- c(10.4, 5.6, 3.1, 6.4, 21.7)
assign("x", c(10.4, 5.6, 3.1, 6.4, 21.7))
c(10.4, 5.6, 3.1, 6.4, 21.7) -> x
y <- c(x, 0, x)
向量运算
加+,减-,乘*,除/,乘方^,整数除法(%/%),求余数(%%)
log, exp, cos, tan, sqrt
向量函数
min(x),max(x),range(x),which.min(x),which.max(x)
sum(x),prod(x)
median(x),mean(x),var(x),sd(x),sort(x)
等差数列,seq(),rep()
逻辑向量 <, <=, >, >=,==,!=,&,|,!,all(),any()
缺失数据
is.na(),is.nan(),is.finite(),is.infinite()
字符型向量
paste()
复数向量
complex(re=x, im=y)
Re(),Im(),Mod(),Arg()
下标操作
x[2],x[x<5],z[is.na(z)],(z+1)[(!is.na(z)) & z>0]
v[c(1,3,5,9)],v[1:5],c("a","b","c")[rep(c(2,1,3), times=3)],v[-(1:5)]
ages["Zhang"],names(fruit)
固有属性
mode(c(1,3,5)>5),is.numeric(z),is.character(z),length(2:4)
as.character(z)
attributes(object),attr(object, name)