Exercises

  1. Open Rstudio, read in the mice package. What data are in the package? (Hint: ?data will give you the help file for the data function). What else is in the package?

  1. Look at the data frame ToothGrowth which is part of the datasets package included with base R. Print the data, look at the help file, do a summary. How would you look at whether higher doses of vitamin C were associated wih longer teeth?

  1. Now look at the table HairEyeColor. Look at the help file and print the data. Why does it print weird? How do you make a data frame containing only data on female students? Can you compute the number of brown-haired students? Which hair/eye/sex color combination has the fewest students?

  1. Make a vector containing the numbers 0 to 0.8 by 0.1. Make a vector repeating the numbers 1,2,3 three times. Make a vector containing the letters A to I. Make a data frame out of these three vectors. Name the columns of the data frame - say, “fractions”, “numbers” and “letters”. Add a column containing the log of the sum of “numbers” and “fractions”. Make a histogram of the logs.

  1. Save a copy of your data frame to the disk. Where is it saved? Where is your working directory? If it isn’t where you want it, move it - say, to a new folder designated for this course

End of practical.