R language vector operations, indexing, matrix indexing

The absolute value of abs(x) is the same as in MATLAB.
sqrt(x) is the same as in MATLAB. The square root is the same as in MATLAB.
log(16,base=2)q is the logarithm with two as the lower 16. The default is the natural logarithm
log10 (10) with 10. For low, you can write
exp(x) to calculate the exponent,
ceiling() returns the smallest integer not less than x,
floor() returns the smallest integer not greater than x,
trunc() returns the integer part
round (vector, digits=2), rounded, after the control returns Reserved digits
signif (vector, digits=2) Reserved decimal digits
sin(x)... Trigonometric function
Insert picture description here

var(x)方差
sd(x)标准差
prod(x)连乘积
quantile(x)#计算分位数
quantile(x,c(0.4,0.5,0.75))#计算4,5,7.5分位数
y=c(1,6,5,8,7,4,3,9)
which.max(y)#返回最大值所在的位置
which(y==3)#返回3所在位置
which(y>5)#返回y中大于5的值所在位置
#有了索引还可以返回向量
y[which(y>5)]

Draw a heat map
heatmap (matrix)
array
Insert picture description here
Matrix index

l=matrix(1:20,4,5,byrow = T)#创建矩阵
l
l[1,2]#索引第一行第二列的数
l[1,c(3,4,5)]#索引第一行第3 4 5的数
l[c(1:4),c(3)]#索引第1到4行第3列的数
l[1,]#索引第一行所有列
l[,1]#索引所有行第一列
l[-2,2]#索引去除第二行第一列的其他数

If the matrix has a name, you can access the elements by name. If the name is a string, add quotation marks.
Let's communicate and learn together
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46445293/article/details/105051110