Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Operations with Matrices | Section
Practice
Projects
Quizzes & Challenges
Quizze
Challenges
/
Essential R Programming for Absolute Beginners - 1768563985826

bookOperations with Matrices

Matrices in R support arithmetic operations, both with single numbers and with built-in functions that summarize their values.

Scalar Operations

Applying an arithmetic operation with a single number affects every element in the matrix.

Example

1234
m <- matrix(1:9, nrow = 3, byrow = TRUE) # Multiply every element by 3 m * 3
copy

Aggregate Functions

Functions like sum() and mean() compute totals or averages across the entire matrix.

Example

123456
m <- matrix(1:9, nrow = 3, byrow = TRUE) # Overall mean of all elements mean(m) # Overall sum of all elements sum(m)
copy

Row and Column Functions

You can also apply these functions to rows or columns separately with rowSums(), rowMeans(), colSums(), and colMeans().

Example

123456
m <- matrix(1:9, nrow = 3, byrow = TRUE) # Column sums colSums(m) # Row means rowMeans(m)
copy

These functions make it easy to analyze matrix data by dimension.

Aufgabe

Swipe to start coding

You have a matrix named m:

2  4  6  8
10 12 14 16

Your tasks are:

  1. Divide each element by 2, then add 1. Reassign the result to the m variable.
  2. Output the matrix m.
  3. Output the column totals of the m matrix.
  4. Output the mean value of all m elements.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 32
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

close

bookOperations with Matrices

Swipe um das Menü anzuzeigen

Matrices in R support arithmetic operations, both with single numbers and with built-in functions that summarize their values.

Scalar Operations

Applying an arithmetic operation with a single number affects every element in the matrix.

Example

1234
m <- matrix(1:9, nrow = 3, byrow = TRUE) # Multiply every element by 3 m * 3
copy

Aggregate Functions

Functions like sum() and mean() compute totals or averages across the entire matrix.

Example

123456
m <- matrix(1:9, nrow = 3, byrow = TRUE) # Overall mean of all elements mean(m) # Overall sum of all elements sum(m)
copy

Row and Column Functions

You can also apply these functions to rows or columns separately with rowSums(), rowMeans(), colSums(), and colMeans().

Example

123456
m <- matrix(1:9, nrow = 3, byrow = TRUE) # Column sums colSums(m) # Row means rowMeans(m)
copy

These functions make it easy to analyze matrix data by dimension.

Aufgabe

Swipe to start coding

You have a matrix named m:

2  4  6  8
10 12 14 16

Your tasks are:

  1. Divide each element by 2, then add 1. Reassign the result to the m variable.
  2. Output the matrix m.
  3. Output the column totals of the m matrix.
  4. Output the mean value of all m elements.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 32
single

single

some-alt