Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Operations with Vectors | Section
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
Essential R Programming for Absolute Beginners - 1768563985826

bookOperations with Vectors

Vectors in R support arithmetic operations. Operations can be performed element by element between two vectors of the same length, or between a vector and a single number (applied to each element).

Element-wise Operations

Vectors of equal length can be combined with arithmetic operators, computing results element by element.

Example

123456
a <- c(10, 20, 30) b <- c(40, 25, 5) # Addition (element by element) c <- a + b c
copy

Scalar Operations

A single number can be combined with a vector, and the operation is applied to every element.

Example

1234567
a <- c(10, 20, 30) b <- c(40, 25, 5) c <- a + b # Multiply each element by 2 d <- c * 2 d
copy

Aggregate Functions

R also has many functions, such as sum() and mean(), that work directly on vectors.

Example

123456789
a <- c(10, 20, 30) b <- c(40, 25, 5) c <- a + b d <- c * 2 # Calculate the sum sum(d) # Calculate the average mean(d)
copy
Завдання

Swipe to start coding

You work at a store. During the day, you were able to sell the following items:

ItemPriceItems sold
Sofa$3405
Armchair$1507
Dining table$1153
Dining chair$4515
Bookshelf$1608

Your task is to:

  1. Construct a vector called sold with the respective values from the Items sold column.
  2. Calculate the revenue by multiplying the prices and sold vectors.
  3. Display the total sum of the revenue vector.

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 20
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

close

bookOperations with Vectors

Свайпніть щоб показати меню

Vectors in R support arithmetic operations. Operations can be performed element by element between two vectors of the same length, or between a vector and a single number (applied to each element).

Element-wise Operations

Vectors of equal length can be combined with arithmetic operators, computing results element by element.

Example

123456
a <- c(10, 20, 30) b <- c(40, 25, 5) # Addition (element by element) c <- a + b c
copy

Scalar Operations

A single number can be combined with a vector, and the operation is applied to every element.

Example

1234567
a <- c(10, 20, 30) b <- c(40, 25, 5) c <- a + b # Multiply each element by 2 d <- c * 2 d
copy

Aggregate Functions

R also has many functions, such as sum() and mean(), that work directly on vectors.

Example

123456789
a <- c(10, 20, 30) b <- c(40, 25, 5) c <- a + b d <- c * 2 # Calculate the sum sum(d) # Calculate the average mean(d)
copy
Завдання

Swipe to start coding

You work at a store. During the day, you were able to sell the following items:

ItemPriceItems sold
Sofa$3405
Armchair$1507
Dining table$1153
Dining chair$4515
Bookshelf$1608

Your task is to:

  1. Construct a vector called sold with the respective values from the Items sold column.
  2. Calculate the revenue by multiplying the prices and sold vectors.
  3. Display the total sum of the revenue vector.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 20
single

single

some-alt