Assignment due Feb. 10
# Confession: There's actually an easier way to change all the *s to NAs that I haven't
# mentioned before now because I wanted you all to learn how to save files as text before
# reading them into R. Sorry.
# Try the following. Note the use of the "na.strings" argument to read.table:
ps1=read.table("http://www.stat.psu.edu/~dhunter/220/files/datasets/ascii/pennstate1.txt",
header=T, na.strings="*")
# If you want to see what other arguments read.table has, type '?read.table'
# Now suppose that you want to get the mean for the "Fastest" column, which contains an NA.
# you can use mean with na.rm=TRUE (the default is FALSE, for some reason):
mean (ps1[,"Fastest"], na.rm=T)
# You can do the same thing with the 'var' function to find the sample variance (which may
# then be used to find the st dev).
sqrt(var(ps1[,"Fastest"], na.rm=T))
# Suppose you want the mean or st dev for just the males. Try this:
attach(ps1)
mean(Fastest[Sex=="Male"], na.rm=T)
# Finally, don't forget about the 'table' command, which will be useful for Exercise 12.74.
Rearrange the data shown in this page excerpt in a tabular format with each child being one case. As a first step, decide what variables are contained in Galton's data. Keep in mind that while some of the variables are recorded explicitly as a number, others are recorded implicitly as position in Galton's records. Note that the data are coded as the height in inches minus 60 --- so add 60 to each number to recover the true height. Create a text file with these data in a tabular format that could be read into R, then print out the result to turn in. You are welcome to use either commas or spaces to separate the data columns, but please in either case make sure that the top row of your file contains the variable names.
Source for figure: James A. Hanley, McGill University. Hanley, James A., "Transmuting" Women into Men: Galton's Family Data on Human Stature, See The American Statistician, Volume 58, Number 3, 1 August 2004, pp. 237-243(7)
| Player | Team | Age | Salary |
|---|---|---|---|
| Pitchers | |||
| Osuna, Antonio | Dodgers | 26 | 1050 |
| Pettitte, Andy | Yankees | 26 | 5950 |
| Outfielders | |||
| Dunwoody, Todd | Marlins | 24 | 222 |
| Sosa, Sammy | Cubs | 30 | 9000 |