← Back to R Course | Chapter 7: Data Structures | Lesson 5 of 7

Arrays क्या हैं

एक array एक matrix जैसा है जिसकी ज़्यादा layers हो सकती हैं, trays के एक stack या cubbies के एक cube की तरह। यह आपको तीन या ज़्यादा directions में data store करने देता है।

In this page:

  1. Arrays
Syntax
r
array_name <- array(data, dim = c(rows, cols, layers))
array_name[row, col, layer]

Arrays

R का एक array एक matrix को दो से ज़्यादा dimensions में generalize करता है, array(data, dim = c(...)) से data को एक multi-dimensional grid में store करते हुए।

Elements हर dimension के लिए एक index specify करके access होते हैं, जैसे a[1, 2, 3]। Arrays matrices या data frames से कम commonly इस्तेमाल होते हैं लेकिन genuinely multi-dimensional data के लिए useful हैं।

Note: एक 2-dimensional array functionally एक matrix जैसा ही है -- matrix() बस एक convenient special case है।

उदाहरण: Arrays

markup
arr <- array(1:24, dim = c(2, 3, 4))

cat("Dimensions:", dim(arr), "\n")
cat("Element at [1,2,3]:", arr[1, 2, 3], "\n")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. सिर्फ दो numbers से index करना, जैसे arr[1, 2], जो एक 3-dimensional array के लिए एक error देता है।
  2. यह मान लेना कि पहली dimension columns की संख्या है, जब order rows, columns, फिर layers है।
  3. ऐसा dim देना जिसका product data length से match न हो, इसलिए values cut या recycle हो जाती हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.