PROGRAMMING-EXERCISE-GROUP-8-2
PROGRAMMING-EXERCISE-GROUP-8-2
GROUP 8 — Daet, Lency May N., Gardoce, Allyssa Lou F., Omandac, Kashie Mae B.,
Paguio, Lebron James N., and Sarmiento, Reinier C.
I. From the SAMPLE DATAV2 data frame, create a new data frame and name it
FSvsGRADE DF. This data frame should include the variables below, with the new
variable name on their left:
· G: GENDER
IV. Extract the 20th to 40th observation of FAVORITE COLOR from the SAMPLE DATAV2
and save it to v1. Name v1 using the names () function with 20-40 that represents 20-40
observation. [2 points for correct code]
V. Create a list of factors of all categorical variables from the SAMPLE DATAV2. Name it
my list. If the categorical variable has ordinal level of measurement, make sure that the
factor is ordered.
VI. Create a vector containing the number of observations for each subset created from
item II. Retain the order. Save it in the variable freq . (Use nrow () function) [2 points for
correct code]
VII. Using the matrix function, create a table that shows the frequency of the students in
their favorite subject group according to gender. The row names should be the gender
(”MALE”, ”FEMALE”), and the column names should be the favorite subject (”ENGLISH”,
”MATH”, ”SCIENCE”). Name the matrix with my matrix. [3 points for correct code]
4.1 Extract the column for English and name it Eng. [1 point for correct code]
4.2 Extract the row for Male and name it m. [1 point for correct code]
VIII. Using the dplyr package, manipulate SAMPLE DATAV2 to create a data frame with
the following conditions and save it in a variable ’NEWDATA’. Manipulate SAMPLE
DATAV2 in the following order: [2 points]
1. The data frame should include all students whose favorite color is either black, blue,
red, or yellow, and whose grades in the three subjects are above 85. [2 points]
2. Add a column with the column name ’Ave.’ This column should contain the average of
the three subjects: Grade in Math, Grade in English, and Grade in Science. [2 points]
3. Add a column with the column name ’Fave Math.’ This column should contain ’T’ if the
favorite subject is ’MATH,’ otherwise ’F.’ [2 points]
4. Arrange the data in descending order based on their average grade in the three
subjects. [2 points]
IX. From NEWDATA data frame in item VIII, compute the mean and the standard deviation
of the average of the three subjects (in ’Ave’ column) for each favorite subject. [4 points]