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

Зміст курсу

Вступ до R: Частина 1

Вступ до R: Частина 1

1. Базовий Синтаксис та Команди
2. Вектори
3. Фактори

Інтервали

Для категоризації числових даних у групи можна використовувати функцію cut() в R, яка призначає кожному числу категорію на основі вказаних інтервалів. Наприклад, якщо у вас є безперервна змінна, як зріст, ви можете категоризувати осіб як 'високі', 'середні' або 'низькі' на основі діапазонів зросту.

1234567
# Vector of heights heights <- c(170, 165, 195, 172, 189, 156, 178, 198, 157, 182, 171, 184, 163, 176, 169, 153) # Convert into factor by cutting into intervals heights_f <- cut(heights, breaks = c(0, 160, 190, 250), labels = c('small', 'medium', 'tall'), ordered_result = T) heights_f # Output the factor variable
copy

For our example of categorizing height: We choose c(0, 160, 190, 250) for breaks to divide the data into three groups: (0, 160], (160, 190], and (190, 250]. We also set ordered_result to TRUE to define a logical order among categories (e.g., small < medium < tall).

Завдання

  • Given a vector of numerical grades, here's how to categorize them as factor levels:
    • [0;60) - F;
    • [60;75) - D;
    • [75;85) - C;
    • [85;95) - B;
    • [95;100) - A.
  • Create a variable grades_f that stores the factor levels with the specified breaks and labels, considering the ordering, and use right = FALSE to include the left boundary of the intervals;
    • breaks - c(0, 60, 75, 85, 95, 100);
    • labels - c('F', 'D', 'C', 'B', 'A');
    • ordered_result - T (to order the factor values);
    • right - F (to include the left boundary of an interval, not right).
  • Output the contents of grades_f.

Завдання

  • Given a vector of numerical grades, here's how to categorize them as factor levels:
    • [0;60) - F;
    • [60;75) - D;
    • [75;85) - C;
    • [85;95) - B;
    • [95;100) - A.
  • Create a variable grades_f that stores the factor levels with the specified breaks and labels, considering the ordering, and use right = FALSE to include the left boundary of the intervals;
    • breaks - c(0, 60, 75, 85, 95, 100);
    • labels - c('F', 'D', 'C', 'B', 'A');
    • ordered_result - T (to order the factor values);
    • right - F (to include the left boundary of an interval, not right).
  • Output the contents of grades_f.
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

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

Секція 3. Розділ 5
toggle bottom row

Інтервали

Для категоризації числових даних у групи можна використовувати функцію cut() в R, яка призначає кожному числу категорію на основі вказаних інтервалів. Наприклад, якщо у вас є безперервна змінна, як зріст, ви можете категоризувати осіб як 'високі', 'середні' або 'низькі' на основі діапазонів зросту.

1234567
# Vector of heights heights <- c(170, 165, 195, 172, 189, 156, 178, 198, 157, 182, 171, 184, 163, 176, 169, 153) # Convert into factor by cutting into intervals heights_f <- cut(heights, breaks = c(0, 160, 190, 250), labels = c('small', 'medium', 'tall'), ordered_result = T) heights_f # Output the factor variable
copy

For our example of categorizing height: We choose c(0, 160, 190, 250) for breaks to divide the data into three groups: (0, 160], (160, 190], and (190, 250]. We also set ordered_result to TRUE to define a logical order among categories (e.g., small < medium < tall).

Завдання

  • Given a vector of numerical grades, here's how to categorize them as factor levels:
    • [0;60) - F;
    • [60;75) - D;
    • [75;85) - C;
    • [85;95) - B;
    • [95;100) - A.
  • Create a variable grades_f that stores the factor levels with the specified breaks and labels, considering the ordering, and use right = FALSE to include the left boundary of the intervals;
    • breaks - c(0, 60, 75, 85, 95, 100);
    • labels - c('F', 'D', 'C', 'B', 'A');
    • ordered_result - T (to order the factor values);
    • right - F (to include the left boundary of an interval, not right).
  • Output the contents of grades_f.

Завдання

  • Given a vector of numerical grades, here's how to categorize them as factor levels:
    • [0;60) - F;
    • [60;75) - D;
    • [75;85) - C;
    • [85;95) - B;
    • [95;100) - A.
  • Create a variable grades_f that stores the factor levels with the specified breaks and labels, considering the ordering, and use right = FALSE to include the left boundary of the intervals;
    • breaks - c(0, 60, 75, 85, 95, 100);
    • labels - c('F', 'D', 'C', 'B', 'A');
    • ordered_result - T (to order the factor values);
    • right - F (to include the left boundary of an interval, not right).
  • Output the contents of grades_f.
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

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

Секція 3. Розділ 5
toggle bottom row

Інтервали

Для категоризації числових даних у групи можна використовувати функцію cut() в R, яка призначає кожному числу категорію на основі вказаних інтервалів. Наприклад, якщо у вас є безперервна змінна, як зріст, ви можете категоризувати осіб як 'високі', 'середні' або 'низькі' на основі діапазонів зросту.

1234567
# Vector of heights heights <- c(170, 165, 195, 172, 189, 156, 178, 198, 157, 182, 171, 184, 163, 176, 169, 153) # Convert into factor by cutting into intervals heights_f <- cut(heights, breaks = c(0, 160, 190, 250), labels = c('small', 'medium', 'tall'), ordered_result = T) heights_f # Output the factor variable
copy

For our example of categorizing height: We choose c(0, 160, 190, 250) for breaks to divide the data into three groups: (0, 160], (160, 190], and (190, 250]. We also set ordered_result to TRUE to define a logical order among categories (e.g., small < medium < tall).

Завдання

  • Given a vector of numerical grades, here's how to categorize them as factor levels:
    • [0;60) - F;
    • [60;75) - D;
    • [75;85) - C;
    • [85;95) - B;
    • [95;100) - A.
  • Create a variable grades_f that stores the factor levels with the specified breaks and labels, considering the ordering, and use right = FALSE to include the left boundary of the intervals;
    • breaks - c(0, 60, 75, 85, 95, 100);
    • labels - c('F', 'D', 'C', 'B', 'A');
    • ordered_result - T (to order the factor values);
    • right - F (to include the left boundary of an interval, not right).
  • Output the contents of grades_f.

Завдання

  • Given a vector of numerical grades, here's how to categorize them as factor levels:
    • [0;60) - F;
    • [60;75) - D;
    • [75;85) - C;
    • [85;95) - B;
    • [95;100) - A.
  • Create a variable grades_f that stores the factor levels with the specified breaks and labels, considering the ordering, and use right = FALSE to include the left boundary of the intervals;
    • breaks - c(0, 60, 75, 85, 95, 100);
    • labels - c('F', 'D', 'C', 'B', 'A');
    • ordered_result - T (to order the factor values);
    • right - F (to include the left boundary of an interval, not right).
  • Output the contents of grades_f.
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

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

Для категоризації числових даних у групи можна використовувати функцію cut() в R, яка призначає кожному числу категорію на основі вказаних інтервалів. Наприклад, якщо у вас є безперервна змінна, як зріст, ви можете категоризувати осіб як 'високі', 'середні' або 'низькі' на основі діапазонів зросту.

1234567
# Vector of heights heights <- c(170, 165, 195, 172, 189, 156, 178, 198, 157, 182, 171, 184, 163, 176, 169, 153) # Convert into factor by cutting into intervals heights_f <- cut(heights, breaks = c(0, 160, 190, 250), labels = c('small', 'medium', 'tall'), ordered_result = T) heights_f # Output the factor variable
copy

For our example of categorizing height: We choose c(0, 160, 190, 250) for breaks to divide the data into three groups: (0, 160], (160, 190], and (190, 250]. We also set ordered_result to TRUE to define a logical order among categories (e.g., small < medium < tall).

Завдання

  • Given a vector of numerical grades, here's how to categorize them as factor levels:
    • [0;60) - F;
    • [60;75) - D;
    • [75;85) - C;
    • [85;95) - B;
    • [95;100) - A.
  • Create a variable grades_f that stores the factor levels with the specified breaks and labels, considering the ordering, and use right = FALSE to include the left boundary of the intervals;
    • breaks - c(0, 60, 75, 85, 95, 100);
    • labels - c('F', 'D', 'C', 'B', 'A');
    • ordered_result - T (to order the factor values);
    • right - F (to include the left boundary of an interval, not right).
  • Output the contents of grades_f.
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 3. Розділ 5
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt