You are on page 1of 2

Discussion Assignment – Unit 2

Factors are qualitative data that are associated with categorization or the description
of an attribute.  Factors are often (but not always) represented with words, like colors
or names of things.  On the other hand, numeric data are generated by numeric
measurements. R can store values as factors or numbers, but sometimes you have a
choice of how to represent values.

1) I have two apples, one banana, one cherry.  Does it make sense to calculate the
"average" of these things?  Would you code that as a factor or a numeric value
in R?

The items “apple”, “banana”, and “cherry” are qualitative and I store them as
factors. Therefore, it does not make sense to calculate the average of these
factors.

> fruits <- as.factor(c("apple", "banana", "apple", "cherry"))

> class(fruits)
[1] "factor"

> table(fruits)
apple banana cherry
2 1 1

2) I have four quiz scores: 94, 93, 85, and 0.  What is the mean (average) of my
quiz scores? Would you code this as a factor or a numeric value in R?

It makes sense to store the quiz scores as numeric and we can even calculate
the average value of the quiz values.

> quiz <- c(94, 93, 85, 0)

> class(quiz)
[1] "numeric"

> mean(quiz)
[1] 68

3) In another class, I received these grades on my quizzes: two As, one B, and one
F. What is the mean (average) of my grades? Would you code that as a factor or
a numeric value in R?

Based on the information provided the grades of the quizzes should be stored
as factors. If we are provided the weight of the grades, we could have equated
the numerical weights of each grade and calculate back to the equivalent letter
grade. Therefore, due to lack of enough information, we cannot calculate the
average of these grades.

> grades <- as.factor(c("A", "B", "A", "F"))

> class(grades)
[1] "factor"

> table(grades)
ABF
211

4) How would you explain the difference in mean values obtained in #2 and #3
above?

The #2 question is very clear to calculate the average of the quizzes as the
values are numeric. But the #3 question has a letter/character grade whose
numeric equivalent is not provided with which we could have calculated the
average and convert back to the letter/character grade equivalent.

You might also like