Зміст курсу
Вступ до R: Частина 1
Вступ до R: Частина 1
Індексація
Чудово! Тепер давайте навчимося змінювати вже створену факторну змінну.
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5)]
When R presents the output, it lists all levels beneath, even though only a couple of categorical values were shown. This feature becomes particularly handy when dealing with extensive data and trying to remember all the unique values is impractical.
If it's not necessary to display every level, you can include the drop = TRUE
(or drop = T
) parameter within the brackets []
. This will show only the levels retrieved from indexing. The same operation as mentioned earlier would be written like this:
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5), drop = T]
Using individual indices may not be practical when you need to extract a series of elements. In R, you can generate a vector of consecutive integers by separating the starting and ending numbers with a colon :
. For instance, 5:10
will produce a sequence 5, 6, 7, 8, 9, 10
. Apply this technique in the upcoming task.
Swipe to show code editor
Considering the same dataset of blood types in a factor format, here are your tasks:
- Display the 3rd, 10th, and 15th elements of
blood_gr
, making sure to drop any unused levels (using thedrop
parameter). - Show every element from the 15th to the 21st, inclusive.
Дякуємо за ваш відгук!
Індексація
Чудово! Тепер давайте навчимося змінювати вже створену факторну змінну.
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5)]
When R presents the output, it lists all levels beneath, even though only a couple of categorical values were shown. This feature becomes particularly handy when dealing with extensive data and trying to remember all the unique values is impractical.
If it's not necessary to display every level, you can include the drop = TRUE
(or drop = T
) parameter within the brackets []
. This will show only the levels retrieved from indexing. The same operation as mentioned earlier would be written like this:
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5), drop = T]
Using individual indices may not be practical when you need to extract a series of elements. In R, you can generate a vector of consecutive integers by separating the starting and ending numbers with a colon :
. For instance, 5:10
will produce a sequence 5, 6, 7, 8, 9, 10
. Apply this technique in the upcoming task.
Swipe to show code editor
Considering the same dataset of blood types in a factor format, here are your tasks:
- Display the 3rd, 10th, and 15th elements of
blood_gr
, making sure to drop any unused levels (using thedrop
parameter). - Show every element from the 15th to the 21st, inclusive.
Дякуємо за ваш відгук!
Індексація
Чудово! Тепер давайте навчимося змінювати вже створену факторну змінну.
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5)]
When R presents the output, it lists all levels beneath, even though only a couple of categorical values were shown. This feature becomes particularly handy when dealing with extensive data and trying to remember all the unique values is impractical.
If it's not necessary to display every level, you can include the drop = TRUE
(or drop = T
) parameter within the brackets []
. This will show only the levels retrieved from indexing. The same operation as mentioned earlier would be written like this:
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5), drop = T]
Using individual indices may not be practical when you need to extract a series of elements. In R, you can generate a vector of consecutive integers by separating the starting and ending numbers with a colon :
. For instance, 5:10
will produce a sequence 5, 6, 7, 8, 9, 10
. Apply this technique in the upcoming task.
Swipe to show code editor
Considering the same dataset of blood types in a factor format, here are your tasks:
- Display the 3rd, 10th, and 15th elements of
blood_gr
, making sure to drop any unused levels (using thedrop
parameter). - Show every element from the 15th to the 21st, inclusive.
Дякуємо за ваш відгук!
Чудово! Тепер давайте навчимося змінювати вже створену факторну змінну.
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5)]
When R presents the output, it lists all levels beneath, even though only a couple of categorical values were shown. This feature becomes particularly handy when dealing with extensive data and trying to remember all the unique values is impractical.
If it's not necessary to display every level, you can include the drop = TRUE
(or drop = T
) parameter within the brackets []
. This will show only the levels retrieved from indexing. The same operation as mentioned earlier would be written like this:
# Vector of currencies as factor curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Output the third and the fifth values curr_f[c(3,5), drop = T]
Using individual indices may not be practical when you need to extract a series of elements. In R, you can generate a vector of consecutive integers by separating the starting and ending numbers with a colon :
. For instance, 5:10
will produce a sequence 5, 6, 7, 8, 9, 10
. Apply this technique in the upcoming task.
Swipe to show code editor
Considering the same dataset of blood types in a factor format, here are your tasks:
- Display the 3rd, 10th, and 15th elements of
blood_gr
, making sure to drop any unused levels (using thedrop
parameter). - Show every element from the 15th to the 21st, inclusive.