在[之前的文章](https://steemit.com/r/@oflyhigh/r-matrices-part-1)中,我们学习了矩阵的创建、命名行列,以及按下标以及按命名访问。  # 访问方式的深入探索 尽管我们知道了矩阵的按下标和命名方式访问,但是记得学习列表的时候,访问方式才叫丰富呢!比如说: >`mylist<-list('a', 5.2, c(7, 8, 9), 3+4i)` `print(mylist[2])` `print(mylist[c(1,2)])` `print(mylist[c(TRUE, FALSE, TRUE, FALSE)])` `print(mylist[c(-1,-2)])` 那么不难由此疑问,矩阵是否可以如此操作呢?来试试看吧: >`m<-matrix(c(1:12), nrow=3, byrow=TRUE, dimnames=list(c('r1', 'r2', 'r3'), c('c1', 'c2', 'c3', 'c4')))` `print(m)` `print(m[1, 2]) # 访问第一行第二列上的元素` `print(m[c(1,2),c(1,2)]) # 访问第一行和第二行上第一列和第二列元素` `print(m[c(TRUE, TRUE, FALSE),c(TRUE, TRUE, FALSE, TRUE)]) # 关闭第三行,关闭第三列,显示其余内容` `print(m[-3, -3]) # 关闭第三行,关闭第三列,显示其余内容`  # 矩阵的操作 [R - Matrices](https://www.tutorialspoint.com/r/r_matrices.htm)一文中,介绍了Matrices(矩阵) 的加减乘除(`+、-、x、/`)运算,也就是说四则运算。[R - Matrices](https://www.tutorialspoint.com/r/r_matrices.htm)说进行这些运算的两个矩阵必须具有相同行数和列数 >The dimensions (number of rows and columns) should be same for the matrices involved in the operation. 如果行数列数不一致,进行操作时会提示如下信息: >Error in m1 + m2 : non-conformable arrays 好了,我们来规规矩矩的操作一下,示例如下: >`m1<-matrix(c(1:12), nrow=3, byrow=TRUE)` `m2<-matrix(c(1:12), nrow=3, byrow=FALSE)` `print(m1)` `print(m2)` `print(m1+m2)` `print(m1-m2)` `print(m1*m2)` `print(m1/m2)`  # 矩阵的操作(进阶) 有朋友在我[之前的帖子](https://steemit.com/r/@oflyhigh/r-matrices-part-1)里回复,说R的矩阵乘法和数学中矩阵的乘法有些不一样。 我看了一下,类似我们本文中介绍的矩阵乘法,把对应元素相乘,其实属于**`hadamard product(哈达玛积)`**,与之相对的还有**`kronecker product(克罗内克积,也叫直积或张量积)`**,还有**`matmul product(一般矩阵乘积)`**,不过具体都是咋回事,我是搞不懂了,感兴趣的自己研究一下吧。 不过R肯定不止简单地支持哈达玛积,否则岂不是弱爆了?然后我搜索了一下R的矩阵操作,然后我和我的小伙伴们都惊呆了。 <center></center> 我就截了一部分,感兴趣的小伙伴自己来学吧:[Matrix Algebra](https://www.statmethods.net/advstats/matrix.html),这里列出的只是矩阵强大功能的冰山一角,感兴趣的可以参考文末链接。 ---- 好了,今天就到这里。看来学完[R Tutorial](https://www.tutorialspoint.com/r/index.htm),不过是学了个皮毛,何况这个还不知道猴年学完呢,😔 # 相关链接 * [学R:准备工作](https://steemit.com/r/@oflyhigh/r) * [继续学R:安装软件包](https://steemit.com/r/@oflyhigh/5m2s1h-r) * [继续学R:另一款在线R环境](https://steemit.com/r/@oflyhigh/r-r) * [继续学R:R的6大基本数据类型(原子向量)](https://steemit.com/r/@oflyhigh/r-r-6) * [继续学R:Vector(向量) Part 1, 多元素向量创建&类型](https://steemit.com/r/@oflyhigh/r-vector-part-1-cny-and) * [继续学R:Vector(向量) Part 2, 多元素向量访问 & 计算长度](https://steemit.com/r/@oflyhigh/r-vector-part-2-cny-and) * [继续学R:Vector(向量) Part 3, 多元素向量的操作(算术操作&排序)](https://steemit.com/r/@oflyhigh/r-vector-part-3-cny-and) * [继续学R:List(列表) Part 1, 创建列表&命名&访问](https://steemit.com/r/@oflyhigh/r-list-part-1-and-and) * [继续学R:List(列表) Part 2, 列表的操作](https://steemit.com/r/@oflyhigh/r-list-part-2) * [继续学R:Matrices(矩阵) Part 1,创建矩阵&命名&访问](https://steemit.com/r/@oflyhigh/r-matrices-part-1) * https://www.tutorialspoint.com/r/r_matrices.htm * [Matrix Algebra](https://www.statmethods.net/advstats/matrix.html) * [Quick Review of Matrix Algebra in R](https://www.r-bloggers.com/quick-review-of-matrix-algebra-in-r/) * [Matrix Multiplication](http://stat.ethz.ch/R-manual/R-devel/library/base/html/matmult.html)
author | oflyhigh |
---|---|
permlink | r-matrices-part-2-and-and |
category | r |
json_metadata | {"tags":["r","tutorial","programming","cn-programming","cn"],"image":["https://cdn.steemitimages.com/DQmULNEof836YCum6PtcjGH8DLRMXySbL31WY8ZPaGThPJG/image.png","https://cdn.steemitimages.com/DQmdUqKeL9Nq8ZcDz6H9yrsaGQpHnc8WQvk8SXKfh7atQWb/image.png","https://cdn.steemitimages.com/DQmUcP9ZaGfNxxdxhHZ8pD2gJivn2ABdvGozLdGHzymGchn/image.png","https://cdn.steemitimages.com/DQmP6ZTQeDfXuMUCh5C19ijheSn1b3cZgUBWT4dbhPGUZda/image.png"],"links":["https://steemit.com/r/@oflyhigh/r-matrices-part-1","https://www.tutorialspoint.com/r/r_matrices.htm","https://www.statmethods.net/advstats/matrix.html","https://www.tutorialspoint.com/r/index.htm","https://steemit.com/r/@oflyhigh/r","https://steemit.com/r/@oflyhigh/5m2s1h-r","https://steemit.com/r/@oflyhigh/r-r","https://steemit.com/r/@oflyhigh/r-r-6","https://steemit.com/r/@oflyhigh/r-vector-part-1-cny-and","https://steemit.com/r/@oflyhigh/r-vector-part-2-cny-and","https://steemit.com/r/@oflyhigh/r-vector-part-3-cny-and","https://steemit.com/r/@oflyhigh/r-list-part-1-and-and","https://steemit.com/r/@oflyhigh/r-list-part-2","https://www.r-bloggers.com/quick-review-of-matrix-algebra-in-r/","http://stat.ethz.ch/R-manual/R-devel/library/base/html/matmult.html"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-06-04 00:52:00 |
last_update | 2018-06-04 00:52:00 |
depth | 0 |
children | 3 |
last_payout | 2018-06-11 00:52:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 75.680 HBD |
curator_payout_value | 12.974 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,297 |
author_reputation | 6,358,922,462,581,407 |
root_title | "继续学R:Matrices(矩阵) Part 2,矩阵访问方式&矩阵操作&进阶操作" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 59,125,081 |
net_rshares | 24,240,550,331,728 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
adm | 0 | 5,386,136,926,184 | 30% | ||
wongshiying | 0 | 124,777,896 | 100% | ||
mark-waser | 0 | 161,659,802,687 | 100% | ||
slowwalker | 0 | 1,802,456,416,210 | 18% | ||
blockchainbilly | 0 | 19,907,061,450 | 50% | ||
deanliu | 0 | 1,370,247,767,872 | 100% | ||
ace108 | 0 | 341,030,631,608 | 25% | ||
laoyao | 0 | 35,790,086,378 | 100% | ||
somebody | 0 | 1,316,843,575,569 | 100% | ||
midnightoil | 0 | 127,645,083,689 | 100% | ||
xiaohui | 0 | 720,923,351,590 | 100% | ||
oflyhigh | 0 | 2,558,122,410,800 | 100% | ||
xiaokongcom | 0 | 6,611,891,676 | 100% | ||
yulan | 0 | 15,022,563,451 | 100% | ||
chinadaily | 0 | 274,807,153,336 | 100% | ||
helene | 0 | 766,358,683,253 | 100% | ||
ffcrossculture | 0 | 29,058,476,440 | 50% | ||
ethansteem | 0 | 194,336,246,709 | 100% | ||
sweetsssj | 0 | 3,665,195,074,066 | 10% | ||
davidjkelley | 0 | 8,138,915,132 | 100% | ||
digital-wisdom | 0 | 89,278,788,453 | 100% | ||
ethical-ai | 0 | 29,259,968,022 | 100% | ||
jwaser | 0 | 34,798,100,916 | 100% | ||
damarth | 0 | 721,207,416 | 3% | ||
bwaser | 0 | 240,141,425 | 100% | ||
jianghao | 0 | 231,676,028 | 10% | ||
ellepdub | 0 | 2,552,810,820 | 100% | ||
herpetologyguy | 0 | 308,891,323,288 | 100% | ||
handyman | 0 | 241,249,770 | 100% | ||
amylee | 0 | 97,289,015,600 | 100% | ||
mrtv2 | 0 | 55,724,598,867 | 100% | ||
strong-ai | 0 | 24,857,558,172 | 100% | ||
steemtruth | 0 | 2,963,618,781 | 10% | ||
lalala | 0 | 98,922,035,643 | 100% | ||
devilwsy | 0 | 2,256,585,245 | 100% | ||
janiceting | 0 | 2,254,275,521 | 100% | ||
abraomarcos | 0 | 2,394,229,091 | 100% | ||
lydiachan | 0 | 24,957,897,823 | 100% | ||
technoprogressiv | 0 | 18,947,175,082 | 100% | ||
newhope | 0 | 2,102,020,991,184 | 27% | ||
dragon40 | 0 | 2,017,857,803 | 10% | ||
blackbunny | 0 | 92,303,690,977 | 100% | ||
da-dawn | 0 | 1,170,799,447 | 100% | ||
bxt | 0 | 165,033,516,773 | 100% | ||
lingfei | 0 | 63,644,341,440 | 100% | ||
yyyy | 0 | 460,707,126 | 100% | ||
alexis555 | 0 | 1,685,952,941,153 | 25% | ||
austinsandersco | 0 | 758,068,096 | 70% | ||
kingofdew | 0 | 44,974,609,297 | 100% | ||
emcvay | 0 | 176,875,545 | 10% | ||
wylo | 0 | 609,881,658 | 100% | ||
susanlo | 0 | 51,403,416,926 | 100% | ||
jkkim | 0 | 68,876,113 | 10% | ||
ebejammin | 0 | 5,801,475,426 | 100% | ||
nanosesame | 0 | 34,623,370,826 | 30% | ||
cryptohustler | 0 | 27,219,927,644 | 100% | ||
exec | 0 | 84,848,874,095 | 100% | ||
eval | 0 | 811,440,976 | 100% | ||
michaelwilshaw | 0 | 6,990,185,379 | 10% | ||
speeding | 0 | 3,706,109,707 | 100% | ||
walkinharmony | 0 | 8,949,697,405 | 40% | ||
asterix87 | 0 | 13,757,556,104 | 100% | ||
canbethisone | 0 | 17,148,339,463 | 50% | ||
abetterworld | 0 | 2,935,950,908 | 100% | ||
raili | 0 | 10,045,200,462 | 100% | ||
that1consultant | 0 | 302,353,392 | 100% | ||
sanzo | 0 | 277,908,216 | 100% | ||
stenyin | 0 | 200,320,395 | 100% | ||
davaowhenyo | 0 | 610,390,398 | 100% | ||
allenshayzar | 0 | 610,390,398 | 100% | ||
raku | 0 | 613,122,478 | 100% | ||
resteeming | 0 | 610,787,288 | 100% | ||
ravenousappetite | 0 | 610,390,398 | 100% | ||
aabb | 0 | 11,828,499,752 | 100% | ||
catwomanteresa | 0 | 34,238,332,941 | 30% | ||
auntigormint | 0 | 537,652,272 | 100% | ||
mrliga | 0 | 17,245,636,966 | 100% | ||
sweethoney | 0 | 253,884,794 | 100% | ||
liangfengyouren | 0 | 1,279,311,404 | 50% | ||
jiangchen | 0 | 9,956,491,422 | 100% | ||
lancy | 0 | 4,523,835,816 | 92% | ||
bearpaw | 0 | 2,621,872,314 | 100% | ||
nancie | 0 | 484,789,034 | 100% | ||
freedom-fighter | 0 | 610,390,398 | 100% | ||
technologynepal | 0 | 613,122,478 | 100% | ||
chenlocus | 0 | 1,175,088,282 | 40% | ||
davidke20 | 0 | 1,615,955,745 | 10% | ||
rosatravels | 0 | 38,957,982,279 | 20% | ||
khalilad | 0 | 605,130,925 | 100% | ||
ms8988 | 0 | 602,448,519 | 100% | ||
xiaoshancun | 0 | 290,422,417 | 100% | ||
stakuza | 0 | 412,187,813 | 100% | ||
ikonik | 0 | 393,531,737 | 100% | ||
vfxness | 0 | 67,564,598 | 100% | ||
lemminon | 0 | 611,243,358 | 100% | ||
bobdos | 0 | 4,041,343,867 | 10% | ||
heyeshuang | 0 | 650,995,250 | 100% | ||
namchau | 0 | 2,434,851,998 | 70% | ||
razor80 | 0 | 560,225,764 | 100% | ||
fastiduos | 0 | 611,243,358 | 100% | ||
winniex | 0 | 4,688,103,802 | 10% | ||
nitro.live | 0 | 307,220,616 | 100% | ||
drawing-steem | 0 | 60,988,165 | 100% | ||
yaru | 0 | 806,832,195 | 100% | ||
chaerin | 0 | 244,337,171 | 100% | ||
windowglass | 0 | 20,092,594,188 | 50% | ||
cnbuddy | 0 | 3,532,838,071 | 0.1% | ||
chann | 0 | 4,078,700,068 | 16% | ||
coindzs | 0 | 151,560,847 | 100% | ||
saury | 0 | 303,723,844 | 100% | ||
cibc | 0 | 182,272,521 | 100% | ||
ewq | 0 | 129,233,116 | 3% | ||
maiyude | 0 | 6,784,597,411 | 10% | ||
mycat | 0 | 111,737,562 | 12% | ||
historylover | 0 | 397,245,202 | 100% | ||
btccurrency1 | 0 | 52,042,028 | 100% | ||
ethanlee | 0 | 11,439,762,894 | 100% | ||
fishbb | 0 | 383,421,447 | 5% | ||
fredo77200 | 0 | 562,245,686 | 100% | ||
fanso | 0 | 1,200,232,162 | 100% | ||
cryptoknight27 | 0 | 611,001,623 | 100% | ||
abss | 0 | 89,989,068 | 11% | ||
khayziljoy | 0 | 51,975,676 | 100% | ||
hepeng.chn | 0 | 147,372,377 | 100% | ||
fishdd | 0 | 406,413,631 | 5% | ||
wwstreet | 0 | 7,710,064,198 | 37% | ||
hmayak | 0 | 484,615,763 | 100% | ||
agoha | 0 | 222,627,197 | 50% | ||
xiaoyuanwmm | 0 | 983,341,372 | 100% | ||
coder-bts | 0 | 7,371,829,871 | 100% | ||
showshidan | 0 | 183,905,640 | 100% | ||
alijewel | 0 | 530,639,703 | 100% | ||
julian2013 | 0 | 71,353,679 | 25% | ||
antonioprado | 0 | 481,960,578 | 100% |
😀good good study, day day up .
author | hannahwu |
---|---|
permlink | re-oflyhigh-r-matrices-part-2-and-and-20180604t044248806z |
category | r |
json_metadata | {"tags":["r"],"app":"steemit/0.1"} |
created | 2018-06-04 04:42:45 |
last_update | 2018-06-04 04:42:45 |
depth | 1 |
children | 1 |
last_payout | 2018-06-11 04:42:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.189 HBD |
curator_payout_value | 0.063 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 30 |
author_reputation | 44,426,683,145,936 |
root_title | "继续学R:Matrices(矩阵) Part 2,矩阵访问方式&矩阵操作&进阶操作" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 59,147,232 |
net_rshares | 70,277,841,880 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
hannahwu | 0 | 70,277,841,880 | 100% |
来,一起玩
author | oflyhigh |
---|---|
permlink | re-hannahwu-re-oflyhigh-r-matrices-part-2-and-and-20180604t073143246z |
category | r |
json_metadata | {"tags":["r"],"app":"steemit/0.1"} |
created | 2018-06-04 07:31:45 |
last_update | 2018-06-04 07:31:45 |
depth | 2 |
children | 0 |
last_payout | 2018-06-11 07:31:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5 |
author_reputation | 6,358,922,462,581,407 |
root_title | "继续学R:Matrices(矩阵) Part 2,矩阵访问方式&矩阵操作&进阶操作" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 59,163,797 |
net_rshares | 0 |
期待来一篇mac装机教程😄
author | wwstreet |
---|---|
permlink | re-oflyhigh-r-matrices-part-2-and-and-20180604t010835694z |
category | r |
json_metadata | {"tags":["r"],"app":"steemit/0.1"} |
created | 2018-06-04 01:08:36 |
last_update | 2018-06-04 01:08:36 |
depth | 1 |
children | 0 |
last_payout | 2018-06-11 01:08:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.228 HBD |
curator_payout_value | 0.073 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 13 |
author_reputation | 6,778,348,608,939 |
root_title | "继续学R:Matrices(矩阵) Part 2,矩阵访问方式&矩阵操作&进阶操作" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 59,126,542 |
net_rshares | 82,575,669,307 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
oflyhigh | 0 | 62,776,010,080 | 2% | ||
kingwriting | 0 | 19,799,659,227 | 100% |