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

bookIndexing Vector Elements

You can access elements of a vector by their position (numeric index) or by their assigned names.

Note
Note

In R, indices start at 1.

Accessing Single Element

You can extract one element at a time either by its position in the vector or by its assigned name.

Example

1234567
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # First grade grades[1] # Grade for Literature grades['Literature']
copy

Accessing Multiple Elements

You can also select several elements at once by passing a vector of indices or names.

Example

1234567
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Second and third grades grades[c(2,3)] # Grades for Math and Physics grades[c('Math', 'Physics')]
copy
Завдання

Swipe to start coding

You have a vector named prices with each price assigned to a corresponding item name. Your task is to:

  1. Retrieve the price of 'Armchair' using its name rather than its index.
  2. Retrieve the prices for both the 'Dining table' and 'Dining chair' using their indices.

Рішення

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

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

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

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

single

Запитати АІ

expand

Запитати АІ

ChatGPT

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

close

bookIndexing Vector Elements

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

You can access elements of a vector by their position (numeric index) or by their assigned names.

Note
Note

In R, indices start at 1.

Accessing Single Element

You can extract one element at a time either by its position in the vector or by its assigned name.

Example

1234567
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # First grade grades[1] # Grade for Literature grades['Literature']
copy

Accessing Multiple Elements

You can also select several elements at once by passing a vector of indices or names.

Example

1234567
grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Second and third grades grades[c(2,3)] # Grades for Math and Physics grades[c('Math', 'Physics')]
copy
Завдання

Swipe to start coding

You have a vector named prices with each price assigned to a corresponding item name. Your task is to:

  1. Retrieve the price of 'Armchair' using its name rather than its index.
  2. Retrieve the prices for both the 'Dining table' and 'Dining chair' using their indices.

Рішення

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

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

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

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

single

some-alt