MATH 2565 W 2007 Section M QandA

From MathWiki

Questions and Answers:

Table of contents

Sampling

Question 
I tried to get a sample of 30 players from the base.pop data frame, but I can't.
I can get a sample of 30 from the numbers 1 to 322:
sample( 1: 322, 30)
 [1] 177  36  28  81 115 278 196 289 297 231 308 222 320  57  16 127  63  31 180
[20] 101 156 137 254  96  97 218 250  91 291 248

But how do I use these sample indices to select from the base.pop data frame.
Answer 
You need to select rows of 'base.pop' using the row indices generated by 'sample()', i.e.
 base.sample <- base.pop[ sample( 1:322, 30 ), ]
 base.sample

Quiz 1?

> ... I was not able to attend the last class, 
> and I have a couple of question for the upcoming quiz (january 17):
> 
> 1. What material is the quiz based on: the R, or the text book, both?
> 2. Are we writing the quiz on paper or on the computer?
> 
Answer
The quiz is based on the material in Chapter 1 of the text and in Chapters 1 and 2 of the hand out. I hinted that I might include a question similar to the question on smoking that is mentioned on the web. There might also be a question on R, perhaps a question on basic sampling.
The quiz might include a combination of replies on paper and replies on the computer with results e-mailed to me. This will vary from quiz to quiz depending on the questions.

Georges Monette 05:53, 16 Jan 2007 (EST)

Guidelines for wiki assignments

1. When you write a solution in a wiki page include the question. Otherwise the solution is not so useful to other students who later visit the page. They would need to have the textbook with them to make sense of the solution.
2. Be sure to add links to your solution in both http://wiki.math.yorku.ca/index.php/MATH_2565_M_Winter_2007_Solutions_to_Business_Statistics and in your team page, e.g. http://wiki.math.yorku.ca/index.php/Team_Gates.
3. When creating solution pages, be sure to use names that will end up being unique. e.g. Math2565M_Solutions_1.16, etc.
4 Have fun.

Georges Monette 10:58, 16 Jan 2007 (EST)

Using a .csv file from the internet

Question 
I was wondering how to take an excel document similar to http://wiki.math.yorku.ca/images/7/73/MATH_2565_Baseball_Data.csv and download to R in order to make charts and histograms.
Answer 
If the ".csv" spreadsheet happens to be in the right format (variable names on the first row, data from the second row down), all you need to use is the 'read.csv' function that can read a '.csv' file directly from the internet, as follows:
  dd <- read.csv("http://wiki.math.yorku.ca/images/7/73/MATH_2565_Baseball_Data.csv")
  head(dd)
  ... etc.
If the file needs editing before it can be used to create an R data frame, then you could download it first:
  download.file("http://wiki.math.yorku.ca/images/7/73/MATH_2565_Baseball_Data.csv", "/local.csv")
Then you open 'local.csv' with Excel in your root directory, edit it, save it as a '.csv' file, and then read it into R:
  dd <- read.csv("/local.csv")
  ... etc.

How do I upload a graph to wiki

See R: Q and A#Uploading plots to a wiki page

How do I upload a .csv file to the wiki so others can use it

See R:_Q_and_A#Uploading_a_.csv_data_frame_and_reading_it_in_R