Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Підсумок | Фактори
Вступ до R: Частина 1

book
Підсумок

Якщо ви хочете підрахувати кількість входжень кожного значення у векторі, функція summary() є саме тим, що вам потрібно.

# Factor variable
curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK',
'CHF', 'EUR', 'AUD', 'EUR'))
# Show summary
summary(curr_f)
12345
# Factor variable curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Show summary summary(curr_f)
copy

Remember, the sequence of the levels reported by summary() corresponds to the order defined when you used the factor() function. If no order is defined, it defaults to numerical or alphabetical order.

Завдання

Swipe to start coding

For the grades data mentioned earlier, compute the frequency of each grade within the grades_f factor.

Рішення

# Vector of grades and converting into factor
grades <- c("A","F","C","C","F","A","F","F","B",
"C","D","D","B","A","B","D","F","A",
"B","A","A","C","F","A","D","C")
grades_f <- factor(grades, labels = c('F', 'D', 'C', 'B', 'A'), ordered = T)
# Output the quantity of each possible value in grades_f
summary(grades_f)
Все було зрозуміло?

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

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

Секція 3. Розділ 4
# Vector of grades and converting into factor
grades <- c("A","F","C","C","F","A","F","F","B",
"C","D","D","B","A","B","D","F","A",
"B","A","A","C","F","A","D","C")
grades_f <- factor(grades, labels = c('F', 'D', 'C', 'B', 'A'), ordered = T)
# Output the quantity of each possible value in grades_f
___(___)
toggle bottom row
some-alt