Модифікація
Чудово! Тепер ви знаєте, як створити вектор, назвати його значення та витягти елементи з нього. Наступним кроком, який ми розглянемо, буде зміна вектора шляхом додавання нових елементів до нього або видалення існуючих.
1234567# Vector of grades and names grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Add new value using vectors grades <- c(grades, 60) # Add new value names(grades)[length(grades)] <- 'Philosophy' # Add name grades # Output the vector
Наприклад, застосуємо ці методи, використовуючи приклад із оцінками, додавши нову оцінку 60
для предмету 'Філософія'
. Перший метод полягає у використанні векторів:
12345678# Vector of grades and names grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Add new value using vectors grades <- c(grades, 60) # Add new value names(grades)[length(grades)] <- 'Philosophy' # Add name grades # Output the vector
Тепер спробуємо другий метод, де ми присвоюємо ім'я значенню, коли додаємо його.
Swipe to start coding
- Add a new item named
'Desk'
with a price of135
to the end of theprices
vector using the second method (assigning the name while adding the value). - Update the price of the
'Bookshelf'
to180
. You can use either the index or the name to do this. - Display the modified vector
prices
.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 3.85Awesome!
Completion rate improved to 3.85
Модифікація
Чудово! Тепер ви знаєте, як створити вектор, назвати його значення та витягти елементи з нього. Наступним кроком, який ми розглянемо, буде зміна вектора шляхом додавання нових елементів до нього або видалення існуючих.
1234567# Vector of grades and names grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Add new value using vectors grades <- c(grades, 60) # Add new value names(grades)[length(grades)] <- 'Philosophy' # Add name grades # Output the vector
Наприклад, застосуємо ці методи, використовуючи приклад із оцінками, додавши нову оцінку 60
для предмету 'Філософія'
. Перший метод полягає у використанні векторів:
12345678# Vector of grades and names grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Add new value using vectors grades <- c(grades, 60) # Add new value names(grades)[length(grades)] <- 'Philosophy' # Add name grades # Output the vector
Тепер спробуємо другий метод, де ми присвоюємо ім'я значенню, коли додаємо його.
Swipe to start coding
- Add a new item named
'Desk'
with a price of135
to the end of theprices
vector using the second method (assigning the name while adding the value). - Update the price of the
'Bookshelf'
to180
. You can use either the index or the name to do this. - Display the modified vector
prices
.
Рішення
Дякуємо за ваш відгук!
single
Awesome!
Completion rate improved to 3.85
Модифікація
Свайпніть щоб показати меню
Чудово! Тепер ви знаєте, як створити вектор, назвати його значення та витягти елементи з нього. Наступним кроком, який ми розглянемо, буде зміна вектора шляхом додавання нових елементів до нього або видалення існуючих.
1234567# Vector of grades and names grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Add new value using vectors grades <- c(grades, 60) # Add new value names(grades)[length(grades)] <- 'Philosophy' # Add name grades # Output the vector
Наприклад, застосуємо ці методи, використовуючи приклад із оцінками, додавши нову оцінку 60
для предмету 'Філософія'
. Перший метод полягає у використанні векторів:
12345678# Vector of grades and names grades <- c(80, 75, 95, 100) names(grades) <- c('Math', 'Physics', 'English', 'Literature') # Add new value using vectors grades <- c(grades, 60) # Add new value names(grades)[length(grades)] <- 'Philosophy' # Add name grades # Output the vector
Тепер спробуємо другий метод, де ми присвоюємо ім'я значенню, коли додаємо його.
Swipe to start coding
- Add a new item named
'Desk'
with a price of135
to the end of theprices
vector using the second method (assigning the name while adding the value). - Update the price of the
'Bookshelf'
to180
. You can use either the index or the name to do this. - Display the modified vector
prices
.
Рішення
Дякуємо за ваш відгук!