Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Labeling Vector Elements | Section
Essential R Programming for Absolute Beginners - 1768563985826

bookLabeling Vector Elements

Vectors in R can be labeled so that each value has an associated name. This makes the data easier to interpret, especially when values represent categories such as subjects, products, or months.

Assigning Labels

To label a vector, create a separate vector of names and assign it to the original vector using the names() function. Each label will then correspond to the matching element by position.

Example

Suppose you have grades in several subjects:

This is how you would represent this table in R:

123456
# Create a vector of grades grades <- c(80, 75, 95, 100) # Assign names to the grades names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Display the labeled vector grades
copy

The output displays each grade alongside its corresponding subject, making the results easier to understand.

Завдання

Swipe to start coding

You manage a local furniture store. You have a list of items and their respective prices, as shown below:

ItemPrice
Sofa$340
Armchair$150
Dining table$115
Dining chair$45
Bookshelf$160

Your task is to store the prices in a vector named prices and label each price with the corresponding item:

  1. Construct a vector of prices and store it in the variable prices.
  2. Use the variable items to assign names to the elements in the prices vector.
  3. Display the prices vector.

Рішення

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

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

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

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

single

Запитати АІ

expand

Запитати АІ

ChatGPT

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

close

bookLabeling Vector Elements

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

Vectors in R can be labeled so that each value has an associated name. This makes the data easier to interpret, especially when values represent categories such as subjects, products, or months.

Assigning Labels

To label a vector, create a separate vector of names and assign it to the original vector using the names() function. Each label will then correspond to the matching element by position.

Example

Suppose you have grades in several subjects:

This is how you would represent this table in R:

123456
# Create a vector of grades grades <- c(80, 75, 95, 100) # Assign names to the grades names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Display the labeled vector grades
copy

The output displays each grade alongside its corresponding subject, making the results easier to understand.

Завдання

Swipe to start coding

You manage a local furniture store. You have a list of items and their respective prices, as shown below:

ItemPrice
Sofa$340
Armchair$150
Dining table$115
Dining chair$45
Bookshelf$160

Your task is to store the prices in a vector named prices and label each price with the corresponding item:

  1. Construct a vector of prices and store it in the variable prices.
  2. Use the variable items to assign names to the elements in the prices vector.
  3. Display the prices vector.

Рішення

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

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

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

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

single

some-alt