- Hands-On Geospatial Analysis with R and QGIS
- Shammunul Islam
- 211字
- 2021-06-10 18:44:23
Array
Arrays are also like matrices, but they allow us to have more than two dimensions. The all_prices2 row has prices of different items for January, March, and June 2018. Now, suppose we also want to record prices for 2017. We can do so by using array() and in this case we want to add two 3x3 matrices where the first one corresponds to 2018 and the latter matrix corresponds to 2017. In array(m, n, p), m and n stand for the dimensions of the matrix and p stands for how many matrices we want to store.
In the following example, we define six vectors for three different months for two different years. Now we create an array by combining six different vectors using c() and by using them inside array() as inputs as follows:
# Create six vectors
jan_2018 = c(10, 11, 20)
mar_2018 = c(20, 22, 25)
june_2018 = c(30, 33, 33)
jan_2017 = c(10, 10, 17)
mar_2017 = c(18, 23, 21)
june_2017 = c(25, 31, 35)
# Now combine these vectors into array
combined = array(c(jan_2018, mar_2018, june_2018, jan_2017, mar_2017, june_2017),dim = c(3,3,2))
combined
We can now see that we have two matrices of 3 x 3 dimensions, as in the output as follows:

- 大學(xué)計(jì)算機(jī)基礎(chǔ):基礎(chǔ)理論篇
- 嵌入式系統(tǒng)應(yīng)用
- 計(jì)算機(jī)圖形學(xué)
- 條碼技術(shù)及應(yīng)用
- 系統(tǒng)安裝與重裝
- 大學(xué)C/C++語(yǔ)言程序設(shè)計(jì)基礎(chǔ)
- 菜鳥起飛系統(tǒng)安裝與重裝
- 計(jì)算機(jī)組網(wǎng)技術(shù)
- Dreamweaver+Photoshop+Flash+Fireworks網(wǎng)站建設(shè)與網(wǎng)頁(yè)設(shè)計(jì)完全實(shí)用
- Xilinx FPGA高級(jí)設(shè)計(jì)及應(yīng)用
- Red Hat Enterprise Linux 5.0服務(wù)器構(gòu)建與故障排除
- Eclipse RCP應(yīng)用系統(tǒng)開發(fā)方法與實(shí)戰(zhàn)
- 51單片機(jī)應(yīng)用程序開發(fā)與實(shí)踐
- 基于Quartus Ⅱ的數(shù)字系統(tǒng)Verilog HDL設(shè)計(jì)實(shí)例詳解
- 面向Agent的軟件設(shè)計(jì)開發(fā)方法