Important notes:

(1) for each problem, after you’ve created your final function, provide me with a printout of the

function statements and the created plot(s). DO NOT GIVE ME A SCREEN SHOT of the

function commands. Type its name at the prompt (without parentheses) and the function

commands will appear; select and copy those commands as text and paste them into your

solutions. That way, the grader or I can easily copy your function commands to see if it

works.

(2) Do not accomplish programming tasks by writing lots and lots of if-then statements. if your

program does this or is similarly inefficient we may take a point deduction saying “Make the

computer do the work”.

1. (10 points) Create a function pointslines() with no arguments that constructs the point-andline-types figure shown in section 11.2 of the R Primer, except (IMPORTANT!!) add your

name to the title(s) for both plots.

2. (15 points) In the setting of problem 2 on hwk 2 (the DL enrollments barplot), let’s write a

function called make.DLplot() whose purpose is to make a similar plot in later years,

adapting to new data as it becomes available for an annual report. I’ve started it for you:

function (enrollments) {

# enrollments: numeric vector of DL headcounts by term

# starting Fall 1999

}

Add statements to this function, after the comment, to do the following. After doing each step

below, save the function and check to see if the added command(s) worked. Don’t give me the

intermediate versions, just your final (most successful) function, and at least one plot showing a

successful test run.

a) determine the length of the enrollments vector (call it n)

using only this n and the provided vector enrollments:

b) make the barplot (hint: names.arg=1:n)

c) determine the last term for which enrollments are provided, as either Fall, Spring, or

Summer. (hint: use n%%3, the remainder of n divided by 3)

d) determine the final year for which enrollments are provided. Hint: floor() )

e) place a legend at the topleft of the graph with the revised time range information (similar to

the barplot from hwk 2), e.g. From Fall 1999 to _____ _____. Hint: use paste(), which can

combine character strings with the values of any object(s), converting the latter to character

values.

STAT 540 Hwk 3 p.1

f) add an appropriate title, including your name

Your function must accomplish the task for any numeric enrollment vector passed to it,

without further information. To test your function, I suggest you use the original enrollment

vector from hwk 2 and add made-up numbers, e.g. check1 = c(enrollments,50) and then

> make.DLplot(check1). You might want to add 2, and then 3, values to make sure

your function gets the correct term and year in the legend.

3. (15 points): Modify the function poker() from Ch. 12 of the Primer to a function called

bridge() which deals 13 cards instead of 5. The function should also count the hand’s points

as follows.

a. Highcard.points: score 4 points for each Ace in the hand, 3 points for each King, 2 points

for each Queen, and 1 point for each Jack (add these together). Hint:

table(myhand[,”denom”])

b. Distribution.points: score 3 points for each suit that has no cards in the hand (a “void”),

2 points for each suit that has only 1 card (a “singleton”), and 1 point for each suit that

has only two cards (a “doubleton”). Hint: table(myhand[,”suit”])

The function should return a list including the hand itself (a 13 by 2 data frame), the value of

Highcard.points, and the value of Distribution.points. After you’ve created the function and

checked it, provide me with a printout of the function and at least one example of its output

list.

Extra Credit problem (10 points): modify your function for problem 2 to so that the term

numbers on the horizontal axis are replaced by words “Fa99”, “Sp00”, “Su00” and so on. Make

these labels print perpendicular to the horizontal axis (hint: las). Test your function using the

hwk2 enrollment vector.

STAT 540 Hwk 3 p.2

Order your essay today and save **25%** with the discount code: GREEN