Você está na página 1de 4

Homework 6: Data frames and ggplot2

Submit your homework to blackboard by next Saturday at noon. Your homework file should be titled
lastname_firstname_hw6.R

Data frames. Use the diamonds data frame from the ggplot2 library to help you write the following functions.

1. Write a function that given a data frame extracts the column names and prints the names one column name per
line to the console.
2. Write a function that given a data frame returns the type of each column (numeric, factor, logical, etc.) and
prints the type to the console.
3. Write a function that given a data frame will loop through each numeric column and print the name and mean
of that column.
4. Write a function that given a data frame will loop through each factor column and prints a frequency table for
that column (Hint: look at the table() function).
5. Write a function that given a data frame will loop through each column and print the column name, the most
common element and the number of times that element occurs. Note: If there are multiple elements that
appear the same number of times only return one of them.

ggplot2

Recreate the following plots as best you can using ggplot2 and the diamonds data set.

6.
7.

8.
9.

10.
Extra Credit :