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

Matrices क्या हैं

एक matrix same तरह की value की rows और columns का एक grid है, muffins की एक tray या एक chessboard की तरह। आप इसकी row और column से एक value ढूंढते हैं।

In this page:

  1. Matrices
Syntax
r
matrix_name <- matrix(data, nrow = rows, ncol = cols)
matrix_name[row, col]

Matrices

एक matrix single type की values का एक two-dimensional collection है, matrix(data, nrow, ncol) से बनाया गया।

Elements m[row, col] से access होते हैं, और दूसरे index को blank छोड़कर पूरी row या column select की जा सकती है, जैसे m[1, ]। Matrices %*% से matrix multiplication जैसे standard linear algebra operations support करते हैं।

Note: m[1, ] पूरी पहली row select करता है; m[, 1] पूरा पहला column select करता है।

उदाहरण: Matrices

markup
m <- matrix(1:6, nrow = 2, ncol = 3)
print(m)

cat("Element at row 2, col 3:", m[2, 3], "\n")
print(m[1, ])
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. यह उम्मीद करना कि matrix(1:6, nrow = 2) rows से भरेगा, जब यह column से भरता है जब तक आप byrow = TRUE set न करें।
  2. index करते वक्त comma भूल जाना, जैसे m[2], जो एक row की बजाय position से एक element return करता है; m[2, ] इस्तेमाल करें।
  3. ऐसा data देना जिसकी length dimensions में fit न हो, जो सिर्फ एक warning के साथ values 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.