Course Content
R Introduction: Part I
R Introduction: Part I
Counting Values
If you're looking to count the occurrences of each value within a vector, the summary()
function is exactly what you need.
To tally the frequency of each level within a factor, use the summary()
function with the factor as its argument. This will list the occurrences for each level that the factor can take. For instance:
# Factor variable curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Show summary summary(curr_f)
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.
Task
For the grades data mentioned earlier, compute the frequency of each grade within the grades_f
factor.
Thanks for your feedback!
Counting Values
If you're looking to count the occurrences of each value within a vector, the summary()
function is exactly what you need.
To tally the frequency of each level within a factor, use the summary()
function with the factor as its argument. This will list the occurrences for each level that the factor can take. For instance:
# Factor variable curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Show summary summary(curr_f)
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.
Task
For the grades data mentioned earlier, compute the frequency of each grade within the grades_f
factor.
Thanks for your feedback!
Counting Values
If you're looking to count the occurrences of each value within a vector, the summary()
function is exactly what you need.
To tally the frequency of each level within a factor, use the summary()
function with the factor as its argument. This will list the occurrences for each level that the factor can take. For instance:
# Factor variable curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Show summary summary(curr_f)
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.
Task
For the grades data mentioned earlier, compute the frequency of each grade within the grades_f
factor.
Thanks for your feedback!
If you're looking to count the occurrences of each value within a vector, the summary()
function is exactly what you need.
To tally the frequency of each level within a factor, use the summary()
function with the factor as its argument. This will list the occurrences for each level that the factor can take. For instance:
# Factor variable curr_f <- factor(c('USD', 'EUR', 'AUD', 'NOK', 'CHF', 'EUR', 'AUD', 'EUR')) # Show summary summary(curr_f)
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.
Task
For the grades data mentioned earlier, compute the frequency of each grade within the grades_f
factor.