R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
library(readr)
gilt <- read_csv("GILTdata.csv")
## Parsed with column specification:
## cols(
##   zip = col_integer(),
##   time = col_double(),
##   age = col_integer(),
##   product = col_integer(),
##   MSRP = col_integer(),
##   discountCat = col_character()
## )
head(gilt)
## # A tibble: 6 x 6
##     zip  time   age product  MSRP discountCat
##   <int> <dbl> <int>   <int> <int> <chr>      
## 1 75001  4.62    21       1  1090 low        
## 2 75001  4.62    21       2    75 low        
## 3 75001  4.62    21       3   670 low        
## 4 75001  4.62    21       4    90 low        
## 5 75001  4.62    21       5   270 low        
## 6 75001  4.62    21       6   331 low
summary(gilt)
##       zip             time              age           product    
##  Min.   : 1040   Min.   :  2.517   Min.   :19.00   Min.   :1.00  
##  1st Qu.:27293   1st Qu.:  4.617   1st Qu.:28.00   1st Qu.:2.75  
##  Median :44866   Median :  5.950   Median :33.00   Median :4.50  
##  Mean   :49543   Mean   :  7.463   Mean   :36.16   Mean   :4.50  
##  3rd Qu.:78431   3rd Qu.:  7.812   3rd Qu.:43.00   3rd Qu.:6.25  
##  Max.   :99701   Max.   :106.150   Max.   :77.00   Max.   :8.00  
##       MSRP         discountCat       
##  Min.   :  75.00   Length:4032       
##  1st Qu.:  89.75   Class :character  
##  Median : 300.50   Mode  :character  
##  Mean   : 380.62                     
##  3rd Qu.: 490.00                     
##  Max.   :1090.00
str(gilt)
## Classes 'tbl_df', 'tbl' and 'data.frame':    4032 obs. of  6 variables:
##  $ zip        : int  75001 75001 75001 75001 75001 75001 75001 75001 30066 30066 ...
##  $ time       : num  4.62 4.62 4.62 4.62 4.62 ...
##  $ age        : int  21 21 21 21 21 21 21 21 52 52 ...
##  $ product    : int  1 2 3 4 5 6 7 8 2 3 ...
##  $ MSRP       : int  1090 75 670 90 270 331 89 430 75 670 ...
##  $ discountCat: chr  "low" "low" "low" "low" ...
##  - attr(*, "spec")=List of 2
##   ..$ cols   :List of 6
##   .. ..$ zip        : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ time       : list()
##   .. .. ..- attr(*, "class")= chr  "collector_double" "collector"
##   .. ..$ age        : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ product    : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ MSRP       : list()
##   .. .. ..- attr(*, "class")= chr  "collector_integer" "collector"
##   .. ..$ discountCat: list()
##   .. .. ..- attr(*, "class")= chr  "collector_character" "collector"
##   ..$ default: list()
##   .. ..- attr(*, "class")= chr  "collector_guess" "collector"
##   ..- attr(*, "class")= chr "col_spec"
attach(gilt)
meanMSRP <- mean(MSRP)
meanMSRP
## [1] 380.625
aggregate(. ~ product, gilt[4:5], mean)
##   product MSRP
## 1       1 1090
## 2       2   75
## 3       3  670
## 4       4   90
## 5       5  270
## 6       6  331
## 7       7   89
## 8       8  430

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.