आपकी ऑफलाइन सहायता

BACK
49

सी प्रोग्रामिंग

149

पाइथन प्रोग्रामिंग

49

सी प्लस प्लस

99

जावा प्रोग्रामिंग

149

जावास्क्रिप्ट

49

एंगुलर जे.एस.

69

पी.एच.पी.
माय एस.क्यू.एल.

99

एस.क्यू.एल.

Free

एच.टी.एम.एल.

99

सी.एस.एस.

149

आर प्रोग्रामिंग

39

जे.एस.पी.





डाउनलोड पी.डी.एफ. ई-बुक्स
R - Arrays

R Programming में arrays ये matrices जैसे होते है लेकिन matrices ये two-dimensional होते है और arrays ये दो से ज्यादा dimensions पर sequence या vector पर दिए हुए elements को store कर सकते है |

R में array को create करने के लिए array() function का इस्तेमाल किया जाता है |

Syntax for array() Function R

array(
sequence/vector, 
dim=(no_of_rows, no_of_columns, no_of_matrix), 
dimnames=list(rownames, colnames, matrixnames)
)

Parameters for array() Function in R

sequence/vector : यहाँ पर sequence या vector दिया जाता है |

dim : Optional. dim parameter की value पर create किये जाने वाले rows की संख्या , columns की संख्या और matrices की संख्या दी जाती है |

dimnames : Optional. dimnames parameter पर rows, columns और matrices के लिए नाम दिए जाते है |

Simple Example for array() Function in R

Example पर vector पर दिए हुए elements के 2 rows और 4 columns के 2 matrices create किये गए है |

Source Code :
> array(c(1, 2, 3, 4, 2, 5, 4, 4), dim = c(2,4,2))
, , 1

     [,1] [,2] [,3] [,4]
[1,]    1    3    2    4
[2,]    2    4    5    4

, , 2

     [,1] [,2] [,3] [,4]
[1,]    1    3    2    4
[2,]    2    4    5    4

Example for array() Function with dimnames(Naming rows, columns and matrices) in R

Example पर rows, columns और matrices को dimnames इस parameter की मदद से नाम दिए गए है |

Source Code :
> rownames = c('row1', 'row2')
> colnames = c('col1', 'col2', 'col3', 'col4')
> matnames = c('matrix1', 'matrix2')
> array(c(1, 2, 3, 4, 2, 5, 4, 4),
+ dim = c(2, 4, 2),
+ dimnames = list(rownames, colnames, matnames))
, , matrix1

     col1 col2 col3 col4
row1    1    3    2    4
row2    2    4    5    4

, , matrix2

     col1 col2 col3 col4
row1    1    3    2    4
row2    2    4    5    4

Example for Accessing Array Elements in R

Example पर पहले statement में 2nd matrix के 2nd row और 4th column के element को access किया गया है |

दुसरे statement में 2nd matrix के पूरे 2nd row को access किया गया है |

Source Code :
> arr = array(c(1,2,3,4, 2, 5, 4, 4), dim = c(2,4,2))
> arr[2, 4, 2] #Respectively [2nd row, 4th column, 2nd matrix]
[1] 4
> arr[2, , 2] #Respectively [2nd row, , 2nd matrix]
[1] 2 4 5 4