Problems 1-4 in R