0
0
R Programmingprogramming~15 mins

Why matrices handle tabular math in R Programming - See It in Action

Choose your learning style9 modes available
Why matrices handle tabular math
📖 Scenario: Imagine you run a small shop and you want to keep track of how many items you sold each day. You have two products and three days of sales data. Using a matrix helps you organize this data in rows and columns, just like a table.
🎯 Goal: You will create a matrix to hold sales data, set up a threshold for good sales, find which sales are above that threshold using matrix operations, and finally print the result.
📋 What You'll Learn
Create a matrix called sales with 2 rows and 3 columns using the exact values: 5, 8, 6, 7, 3, 9
Create a variable called threshold and set it to 6
Create a logical matrix called good_sales that is TRUE where sales values are greater than threshold
Print the good_sales matrix
💡 Why This Matters
🌍 Real World
Matrices help organize and analyze tabular data like sales, temperatures, or survey results efficiently.
💼 Career
Understanding matrices and their operations is useful in data analysis, statistics, and many programming jobs involving data.
Progress0 / 4 steps
1
Create the sales matrix
Create a matrix called sales with the values 5, 8, 6, 7, 3, 9 arranged in 2 rows and 3 columns using the matrix() function.
R Programming
Need a hint?

Use matrix(c(5, 8, 6, 7, 3, 9), nrow = 2, ncol = 3, byrow = TRUE) to create the matrix with the exact values.

2
Set the sales threshold
Create a variable called threshold and set it to the number 6.
R Programming
Need a hint?

Just write threshold <- 6 to create the variable.

3
Find good sales with matrix comparison
Create a logical matrix called good_sales that is TRUE where the sales matrix values are greater than the threshold variable.
R Programming
Need a hint?

Use the comparison operator > between sales and threshold to get a logical matrix.

4
Print the good sales matrix
Print the good_sales matrix to see which sales are above the threshold.
R Programming
Need a hint?

Use print(good_sales) to show the matrix.