2016-07-28 104 views
1

我有兩個矩陣如下:添加元素

loweredge 
     [,1] [,2] [,3] 
    [1,] -32.5 87.5 207.5 

SectorAzimuth 
     [,1] [,2] [,3] [,4] [,5] [,6] 
[1,] 10.83 21.66 32.5 43.33 54.16 65 

我想在SectorAzimuth添加所有6個值到loweredge的第一值,則在SectorAzimuth所有6個值添加到第二降低的值以及類似的SectorAzimuth的6個值到降低的第3個值。

任何人都可以給我一些指點嗎?

+0

我知道我可以添加以下loweredge [1,1] + SectorAzimuth,是循環的loweredge的尺寸的情況下? – TheGoat

回答

1

您可以嘗試

loweredge <- matrix(c(-32.5, 87.5, 207.5), nrow = 1) 
SectorAzimuth <- matrix(c(10.83, 21.66, 32.5, 43.33, 54.16, 65), nrow = 1) 

apply(loweredge, MARGIN = 2, FUN = `+`, y = SectorAzimuth) 
     [,1] [,2] [,3] 
[1,] -21.67 98.33 218.33 
[2,] -10.84 109.16 229.16 
[3,] 0.00 120.00 240.00 
[4,] 10.83 130.83 250.83 
[5,] 21.66 141.66 261.66 
[6,] 32.50 152.50 272.50 
+0

或'外(c(SectorAzimuth),c(Lowestge),\'+ \')' – Frank

+0

感謝球員們的幫助,非常感謝。 – TheGoat