# MATH 2565 W 2007 Section M R scripts

## Special functions for MATH 2565 Section M

You can load functions in 'fun.R' with

```  source("http://www.math.yorku.ca/~georges/R/fun.R")
```

If you want to use these functions when you are not connected to the internet you might like to download the file and copy it to your computer:

```  download.file( "http://www.math.yorku.ca/~georges/R/fun.R", "/fun.R")

```

Then you can load the functions with

```  source("/fun.R")
```

This installs the file in your 'root' directory. You might prefer to put it elsewhere. You will want to download the file periodically to make sure you have the lastest version.

Most of the functions in 'fun.R' are quite simple and can be understood by looking at the body of the function. Brief help information should be accumulated as we go along in R functions: fun.R help.

## Data for MATH 2565 Section M

### Baseball data

• Salaries and other information from 1986 and 1987
``` base.data <- read.csv("http://wiki.math.yorku.ca/images/7/73/MATH_2565_Baseball_Data.csv")
```

## R scripts for MATH 2565 Section M

• Chapter 1: R Script for random sampling
• Chapter 2: R Script for Charts and Histograms
• R techniques in this script:
• Creating a function to do a customized report
• Creating bins with 'cut'
• Chapter 3: R Script for Numerical Measures
• R techniques in this script:
• 'sapply' to apply a function to each variable of a data frame
• Using na.rm to drop NAs
• par( mfrow = c(3,2) ) to get multiple plots per page
• 'abline' to add lines to a plot
• 'legend' to add a legend to a plot
• Creating your own function to drop NAs
• 'split' to create a list of values
• Selecting elements of the list
• Ordering the elements of the list