This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.

  1. Import the data
cacoa <- read.csv("flavors_of_cacao.csv")
  1. Describe the Data
str(cacoa)
## 'data.frame':    1795 obs. of  9 variables:
##  $ Company...Maker.if.known.       : chr  "A. Morin" "A. Morin" "A. Morin" "A. Morin" ...
##  $ Specific.Bean.Origin.or.Bar.Name: chr  "Agua Grande" "Kpime" "Atsane" "Akata" ...
##  $ REF                             : int  1876 1676 1676 1680 1704 1315 1315 1315 1319 1319 ...
##  $ Review.Date                     : int  2016 2015 2015 2015 2015 2014 2014 2014 2014 2014 ...
##  $ Cocoa.Percent                   : chr  "63%" "70%" "70%" "70%" ...
##  $ Company.Location                : chr  "France" "France" "France" "France" ...
##  $ Rating                          : num  3.75 2.75 3 3.5 3.5 2.75 3.5 3.5 3.75 4 ...
##  $ Bean.Type                       : chr  " " " " " " " " ...
##  $ Broad.Bean.Origin               : chr  "Sao Tome" "Togo" "Togo" "Togo" ...
  1. Summarize the data
summary(cacoa)
##  Company...Maker.if.known. Specific.Bean.Origin.or.Bar.Name      REF      
##  Length:1795               Length:1795                      Min.   :   5  
##  Class :character          Class :character                 1st Qu.: 576  
##  Mode  :character          Mode  :character                 Median :1069  
##                                                             Mean   :1036  
##                                                             3rd Qu.:1502  
##                                                             Max.   :1952  
##   Review.Date   Cocoa.Percent      Company.Location       Rating     
##  Min.   :2006   Length:1795        Length:1795        Min.   :1.000  
##  1st Qu.:2010   Class :character   Class :character   1st Qu.:2.875  
##  Median :2013   Mode  :character   Mode  :character   Median :3.250  
##  Mean   :2012                                         Mean   :3.186  
##  3rd Qu.:2015                                         3rd Qu.:3.500  
##  Max.   :2017                                         Max.   :5.000  
##   Bean.Type         Broad.Bean.Origin 
##  Length:1795        Length:1795       
##  Class :character   Class :character  
##  Mode  :character   Mode  :character  
##                                       
##                                       
## 
  1. Generate the cross-tabulation
table(cacoa$Company.Location)
## 
##         Amsterdam         Argentina         Australia           Austria 
##                 4                 9                49                26 
##           Belgium           Bolivia            Brazil            Canada 
##                40                 2                17               125 
##             Chile          Colombia        Costa Rica    Czech Republic 
##                 2                23                 9                 1 
##           Denmark Domincan Republic           Ecuador           Eucador 
##                15                 5                54                 1 
##              Fiji           Finland            France           Germany 
##                 4                 2               156                35 
##             Ghana           Grenada         Guatemala          Honduras 
##                 1                 3                10                 6 
##           Hungary           Iceland             India           Ireland 
##                22                 3                 1                 4 
##            Israel             Italy             Japan         Lithuania 
##                 9                63                17                 6 
##        Madagascar        Martinique            Mexico       Netherlands 
##                17                 1                 4                 4 
##       New Zealand         Niacragua         Nicaragua              Peru 
##                17                 1                 5                17 
##       Philippines            Poland          Portugal       Puerto Rico 
##                 1                 8                 3                 4 
##            Russia          Sao Tome          Scotland         Singapore 
##                 1                 4                10                 3 
##      South Africa       South Korea             Spain         St. Lucia 
##                 3                 5                25                 2 
##          Suriname            Sweden       Switzerland              U.K. 
##                 1                 5                38                96 
##            U.S.A.         Venezuela           Vietnam             Wales 
##               764                20                11                 1
x_vec <- c(1:4)
x_vec
## [1] 1 2 3 4
  1. Indexing
cacoa[8,9]
## [1] "Venezuela"
  1. Sub-setting based on criteria
subset(cacoa,
       (Rating >= 4) & (Company.Location %in% c("Italy", "U.S.A.")))

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.