將txt讀取
data = read.table("ex12-11.txt",header=t)
> data
infant age weight systolicbp
1 1 3 2.61 80
2 2 4 2.67 90
資料轉矩陣
m<-as.matrix(data)
> m
infant age weight systolicbp
[1,] 1 3 2.61 80
[2,] 2 4 2.67 90
提取矩陣的age和weight列
m[,2:3]#age在矩陣中為第2列,weight是第三列
這裡注意和python不同,不是從0開始數的。
4. 矩陣轉置
t(m)
矩陣乘法
m%*%n #%*%表示矩陣的乘法
矩陣的逆
library(mass)
ginv(m) #m是矩陣
7.矩陣加一列
x=cbind(1,m)
> x
age weight
[1,] 1 3 2.61
[2,] 1 4 2.67
other <- c( 55,66 )
x=cbind(other,m)
> x
age weight
[1,] 55 3 2.61
[2,] 66 4 2.67
R語言 矩陣的基礎運算
先建立乙個2 5的矩陣a x c 1 10 a matrix x,ncol 2,nrow 5,byrow t a 1 2 1,1 2 2,3 4 3,5 6 4,7 8 5,9 10再建立乙個矩陣b x c 1 10 b matrix x,ncol 2,nrow 5 b 1 2 1,1 6 2,2 ...
列印矩陣 旋轉矩陣 矩陣查詢(c )
2 旋轉正方形矩陣 vector方法 後續更新 3 之列印 後續更新 4 矩陣查詢 後續更新 不能想如何進行座標位置變換到下乙個,很難。應該考慮資料狀況,從巨集觀上進行分解。若傳入陣列為二維 int a,且不能確定長和寬。way1 下面方法也能獲取長度 1 int lines sizeof a si...
推到 旋轉矩陣公式 旋轉矩陣公式推導
1.在二維平面中 如下圖所示,在xoyxoy平面中有一向量op x,y top x,y t,旋轉 角後變為向量op x y top x y t。據圖可得 x op cos y op sin x op cos y op sin 經旋轉 角後有 x op cos op cos cos sin sin x...