SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
Stat405       Functions & for loops


                            Hadley Wickham
Monday, 13 September 2010
1. Projects
               2. Function structure and calling
                  conventions
               3. Practice writing functions
               4. For loops



Monday, 13 September 2010
Functions

Monday, 13 September 2010
Basic structure
                   • Name
                   • Input arguments
                        • Names/positions
                        • Defaults
                   • Body
                   • Output (final result)


Monday, 13 September 2010
calculate_prize <- function(windows) {
       payoffs <- c("DD" = 800, "7" = 80, "BBB" = 40,
         "BB" = 25, "B" = 10, "C" = 10, "0" = 0)

         same <- length(unique(windows)) == 1
         allbars <- all(windows %in% c("B", "BB", "BBB"))

         if (same) {
           prize <- payoffs[windows[1]]
         } else if (allbars) {
           prize <- 5
         } else {
           cherries <- sum(windows == "C")
           diamonds <- sum(windows == "DD")

             prize <- c(0, 2, 5)[cherries + 1] *
               c(1, 2, 4)[diamonds + 1]
         }
         prize
     }

Monday, 13 September 2010
calculate_prize <- function(windows) {
       payoffs <- c("DD" = 800, "7" = 80, "BBB" = 40,
                                arguments
        name = 25, "B" = 10, "C" = 10, "0" = 0)
         "BB"

         same <- length(unique(windows)) == 1
         allbars <- all(windows %in% c("B", "BB", "BBB"))

      if (same) {
        prize <- payoffs[windows[1]]
      } else if (allbars) {
        prize <- 5
      } else {
  always indent <- sum(windows == "C")
        cherries
     inside {}! <- sum(windows == "DD")
        diamonds

             prize <- c(0, 2, 5)[cherries + 1] *
               c(1, 2, 4)[diamonds + 1]
         }
         prize
     }
         last value in function is result
Monday, 13 September 2010
mean <- function(x) {
       sum(x) / length(x)
     }
     mean(1:10)

     mean <- function(x, na.rm = TRUE) {
       if (na.rm) x <- x[!is.na(x)]
       sum(x) / length(x)
     }
     mean(c(NA, 1:9))




Monday, 13 September 2010
mean <- function(x) {
       sum(x) / length(x)
     }
     mean(1:10)
                                 default value

     mean <- function(x, na.rm = TRUE) {
       if (na.rm) x <- x[!is.na(x)]
       sum(x) / length(x)
     }
     mean(c(NA, 1:9))




Monday, 13 September 2010
# Function: mean
     str(mean)
     mean

     args(mean)
     formals(mean)
     body(mean)




Monday, 13 September 2010
Function arguments
                   Every function argument has a name and
                   a position. When calling, matches exact
                   name, then partial name, then position.
                   Rule of thumb: for common functions,
                   position based matching is ok for required
                   arguments. Otherwise use names
                   (abbreviated as long as clear).


Monday, 13 September 2010
mean(c(NA, 1:9), na.rm = T)

     # Confusing in this case, but often saves typing
     mean(c(NA, 1:9), na = T)

     # Generally don't need to name all arguments
     mean(x = c(NA, 1:9), na.rm = T)

     # Unusual orders best avoided, but
     # illustrate the principle
     mean(na.rm = T, c(NA, 1:9))
     mean(na = T, c(NA, 1:9))


Monday, 13 September 2010
# Overkill
     qplot(x = price, y = carat, data = diamonds)

     # Don't need to supply defaults
     mean(c(NA, 1:9), na.rm = F)

     # Need to remember too much about mean
     mean(c(NA, 1:9), , T)

     # Don't abbreviate too much!
     mean(c(NA, 1:9), n = T)



Monday, 13 September 2010
f <- function(a = 1, abcd = 1, abdd = 1) {
       print(a)
       print(abcd)
       print(abdd)
     }

     f(a = 5)
     f(ab = 5)
     f(abc = 5)




Monday, 13 September 2010
Your turn

                   Write a function to calculate the variance
                   of a vector. Make sure it has a na.rm
                   argument.
                   Write the function in your text editor, then
                   copy into R.



Monday, 13 September 2010
Strategy
                   Always want to start simple: start with
                   test values and get the body of the
                   function working first.
                   Check each step as you go.
                   Don’t try and do too much at once!
                   Create the function once everything
                   works.


Monday, 13 September 2010
x <- 1:10
     sum((x - mean(x)) ^ 2) / (length(x) - 1)

     var <- function(x) sum((x - mean(x)) ^ 2) / (length(x) - 1)

     x <- c(1:10, NA)
     var(x)

     na.rm <- TRUE
     if (na.rm) {
       x <- x[!is.na(x)]
     }
     var <- function(x, na.rm = F) {
       if (na.rm) {
         x <- x[!is.na(x)]
       }
       sum((x - mean(x)) ^ 2) / (length(x) - 1)
     }

Monday, 13 September 2010
Testing
                   Always a good idea to test your code.
                   We have a prebuilt set of test cases: the
                   prize column in slots.csv
                   So for each row in slots.csv, we need to
                   calculate the prize and compare it to the
                   actual. (Hopefully they will be same!)



Monday, 13 September 2010
For loops
             print(1)
             print(2)
             print(3)            for(value in 1:10)
             print(4)            {
             print(5)              print(value)
             print(6)            }
             print(7)
             print(8)
             print(9)
             print(10)


Monday, 13 September 2010
For loops
               cuts <- levels(diamonds$cut)
               for(cut in cuts) {
                 selected <- diamonds$price[diamonds$cut == cut]
                 print(cut)
                 print(mean(selected))
               }
               # Have to do something with output!




Monday, 13 September 2010
# Common pattern: create object for output,
     # then fill with results

     cuts <- levels(diamonds$cut)
     means <- rep(NA, length(cuts))

     for(i in seq_along(cuts)) {
       sub <- diamonds[diamonds$cut == cuts[i], ]
       means[i] <- mean(sub$price)
     }

     # We will learn more sophisticated ways to do this
     # later on, but this is the most explicit


Monday, 13 September 2010
# Common pattern: create object for output,
     # then fill with results

     cuts <- levels(diamonds$cut)
     means <- rep(NA, length(cuts))

     for(i in seq_along(cuts)) { Why use i and not cut?
       sub <- diamonds[diamonds$cut == cuts[i], ]
       means[i] <- mean(sub$price)
     }

     # We will learn more sophisticated ways to do this
     # later on, but this is the most explicit


Monday, 13 September 2010
seq_len(5)
     seq_len(10)
     n <- 10
     seq_len(10)

     seq_along(1:10)
     seq_along(1:10 * 2)




Monday, 13 September 2010
Your turn


                   For each diamond colour, calculate the
                   median price and carat size




Monday, 13 September 2010
colours <- levels(diamonds$color)
     n <- length(colours)
     mprice <- rep(NA, n)
     mcarat <- rep(NA, n)

     for(i in seq_len(n)) {
       set <- diamonds[diamonds$color == colours[i], ]
       mprice[i] <- median(set$price)
       mcarat[i] <- median(set$carat)
     }

     results <- data.frame(colours, mprice, mcarat)


Monday, 13 September 2010
Back to slots...
                   For each row, calculate the prize and save
                   it, then compare calculated prize to actual
                   prize


                   Question: given a row, how can we
                   extract the slots in the right form for the
                   function?


Monday, 13 September 2010
slots <- read.csv("slots.csv")


         i <- 334
         slots[i, ]
         slots[i, 1:3]
         str(slots[i, 1:3])
         as.character(slots[i, 1:3])
         c(as.character(slots[i, 1]), as.character(slots[i, 2]),
         as.character(slots[i, 3]))


         slots <- read.csv("slots.csv", stringsAsFactors = F)
         str(slots[i, 1:3])
         as.character(slots[i, 1:3])


         calculate_prize(as.character(slots[i, 1:3]))

Monday, 13 September 2010
# Create space to put the results
     slots$check <- NA

     # For each row, calculate the prize
     for(i in seq_len(nrow(slots))) {
       w <- as.character(slots[i, 1:3])
       slots$check[i] <- calculate_prize(w)
     }

     # Check with known answers
     subset(slots, prize != prize_c)
     # Uh oh!


Monday, 13 September 2010
# Create space to put the results
     slots$check <- NA

     # For each row, calculate the prize
     for(i in seq_len(nrow(slots))) {
       w <- as.character(slots[i, 1:3])
       slots$check[i] <- calculate_prize(w)
     }

     # Check with known answers
     subset(slots, prize != prize_c)
     # Uh oh!
                             What is the problem? Think
                             about the most general case
Monday, 13 September 2010
DD DD DD                  800
                                            windows <- c("DD", "C", "C")
             7   7   7                 80   # How can we calculate the
            BBB BBB BBB                40   # payoff?
            BB BB BB                   25
             B   B   B                 10
             C   C   C                 10
            Any bar Any bar Any bar     5
                C           C   *       5
                C           *   C       5
                C           *   *       2
                                            DD doubles any winning
                *           C   *       2   combination. Two DD
                *           *   C       2   quadruples. DD is wild
Monday, 13 September 2010
Homework

                   What did we miss? Find out the problem
                   with our scoring function and fix it.




Monday, 13 September 2010

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
 
04 reports
04 reports04 reports
04 reports
 
TensorFlow Tutorial
TensorFlow TutorialTensorFlow Tutorial
TensorFlow Tutorial
 
SAT/SMT solving in Haskell
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in Haskell
 
Marimba - A MapReduce-based Programming Model for Self-maintainable Aggregate...
Marimba - A MapReduce-based Programming Model for Self-maintainable Aggregate...Marimba - A MapReduce-based Programming Model for Self-maintainable Aggregate...
Marimba - A MapReduce-based Programming Model for Self-maintainable Aggregate...
 
Slides
SlidesSlides
Slides
 
Gentlest Introduction to Tensorflow
Gentlest Introduction to TensorflowGentlest Introduction to Tensorflow
Gentlest Introduction to Tensorflow
 
Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Gentlest Introduction to Tensorflow - Part 3
Gentlest Introduction to Tensorflow - Part 3Gentlest Introduction to Tensorflow - Part 3
Gentlest Introduction to Tensorflow - Part 3
 
04 Reports
04 Reports04 Reports
04 Reports
 
Python book
Python bookPython book
Python book
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
TensorFlow in Practice
TensorFlow in PracticeTensorFlow in Practice
TensorFlow in Practice
 
The Ring programming language version 1.10 book - Part 127 of 212
The Ring programming language version 1.10 book - Part 127 of 212The Ring programming language version 1.10 book - Part 127 of 212
The Ring programming language version 1.10 book - Part 127 of 212
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
 
Gentlest Introduction to Tensorflow - Part 2
Gentlest Introduction to Tensorflow - Part 2Gentlest Introduction to Tensorflow - Part 2
Gentlest Introduction to Tensorflow - Part 2
 
Python Day1
Python Day1Python Day1
Python Day1
 
Hyrbid Data Models (relational + json)
Hyrbid Data Models (relational + json)Hyrbid Data Models (relational + json)
Hyrbid Data Models (relational + json)
 

Andere mochten auch (8)

25 Testing
25 Testing25 Testing
25 Testing
 
02 Large
02 Large02 Large
02 Large
 
12 Ddply
12 Ddply12 Ddply
12 Ddply
 
13 Ddply
13 Ddply13 Ddply
13 Ddply
 
09 Wickham, Hadley
09 Wickham, Hadley09 Wickham, Hadley
09 Wickham, Hadley
 
01 intro
01 intro01 intro
01 intro
 
06 Data
06 Data06 Data
06 Data
 
27 development
27 development27 development
27 development
 

Ähnlich wie 08 functions

INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
John De Goes
 
Presenting Your Code
Presenting Your CodePresenting Your Code
Presenting Your Code
moto
 

Ähnlich wie 08 functions (20)

07 problem-solving
07 problem-solving07 problem-solving
07 problem-solving
 
22 spam
22 spam22 spam
22 spam
 
06 data
06 data06 data
06 data
 
Clojure night
Clojure nightClojure night
Clojure night
 
Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013
 
10 simulation
10 simulation10 simulation
10 simulation
 
10 simulation
10 simulation10 simulation
10 simulation
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
09 Simulation
09 Simulation09 Simulation
09 Simulation
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
 
11 Data Structures
11 Data Structures11 Data Structures
11 Data Structures
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
 
R Basics
R BasicsR Basics
R Basics
 
Graph Database Query Languages
Graph Database Query LanguagesGraph Database Query Languages
Graph Database Query Languages
 
19 tables
19 tables19 tables
19 tables
 
Presenting Your Code
Presenting Your CodePresenting Your Code
Presenting Your Code
 
Modern JavaScript - Modern ES6+ Features
Modern JavaScript - Modern ES6+ FeaturesModern JavaScript - Modern ES6+ Features
Modern JavaScript - Modern ES6+ Features
 

Mehr von Hadley Wickham (20)

27 development
27 development27 development
27 development
 
24 modelling
24 modelling24 modelling
24 modelling
 
23 data-structures
23 data-structures23 data-structures
23 data-structures
 
Graphical inference
Graphical inferenceGraphical inference
Graphical inference
 
R packages
R packagesR packages
R packages
 
21 spam
21 spam21 spam
21 spam
 
20 date-times
20 date-times20 date-times
20 date-times
 
18 cleaning
18 cleaning18 cleaning
18 cleaning
 
17 polishing
17 polishing17 polishing
17 polishing
 
16 critique
16 critique16 critique
16 critique
 
15 time-space
15 time-space15 time-space
15 time-space
 
14 case-study
14 case-study14 case-study
14 case-study
 
13 case-study
13 case-study13 case-study
13 case-study
 
12 adv-manip
12 adv-manip12 adv-manip
12 adv-manip
 
11 adv-manip
11 adv-manip11 adv-manip
11 adv-manip
 
11 adv-manip
11 adv-manip11 adv-manip
11 adv-manip
 
09 bootstrapping
09 bootstrapping09 bootstrapping
09 bootstrapping
 
03 extensions
03 extensions03 extensions
03 extensions
 
02 large
02 large02 large
02 large
 
25 fin
25 fin25 fin
25 fin
 

08 functions

  • 1. Stat405 Functions & for loops Hadley Wickham Monday, 13 September 2010
  • 2. 1. Projects 2. Function structure and calling conventions 3. Practice writing functions 4. For loops Monday, 13 September 2010
  • 4. Basic structure • Name • Input arguments • Names/positions • Defaults • Body • Output (final result) Monday, 13 September 2010
  • 5. calculate_prize <- function(windows) { payoffs <- c("DD" = 800, "7" = 80, "BBB" = 40, "BB" = 25, "B" = 10, "C" = 10, "0" = 0) same <- length(unique(windows)) == 1 allbars <- all(windows %in% c("B", "BB", "BBB")) if (same) { prize <- payoffs[windows[1]] } else if (allbars) { prize <- 5 } else { cherries <- sum(windows == "C") diamonds <- sum(windows == "DD") prize <- c(0, 2, 5)[cherries + 1] * c(1, 2, 4)[diamonds + 1] } prize } Monday, 13 September 2010
  • 6. calculate_prize <- function(windows) { payoffs <- c("DD" = 800, "7" = 80, "BBB" = 40, arguments name = 25, "B" = 10, "C" = 10, "0" = 0) "BB" same <- length(unique(windows)) == 1 allbars <- all(windows %in% c("B", "BB", "BBB")) if (same) { prize <- payoffs[windows[1]] } else if (allbars) { prize <- 5 } else { always indent <- sum(windows == "C") cherries inside {}! <- sum(windows == "DD") diamonds prize <- c(0, 2, 5)[cherries + 1] * c(1, 2, 4)[diamonds + 1] } prize } last value in function is result Monday, 13 September 2010
  • 7. mean <- function(x) { sum(x) / length(x) } mean(1:10) mean <- function(x, na.rm = TRUE) { if (na.rm) x <- x[!is.na(x)] sum(x) / length(x) } mean(c(NA, 1:9)) Monday, 13 September 2010
  • 8. mean <- function(x) { sum(x) / length(x) } mean(1:10) default value mean <- function(x, na.rm = TRUE) { if (na.rm) x <- x[!is.na(x)] sum(x) / length(x) } mean(c(NA, 1:9)) Monday, 13 September 2010
  • 9. # Function: mean str(mean) mean args(mean) formals(mean) body(mean) Monday, 13 September 2010
  • 10. Function arguments Every function argument has a name and a position. When calling, matches exact name, then partial name, then position. Rule of thumb: for common functions, position based matching is ok for required arguments. Otherwise use names (abbreviated as long as clear). Monday, 13 September 2010
  • 11. mean(c(NA, 1:9), na.rm = T) # Confusing in this case, but often saves typing mean(c(NA, 1:9), na = T) # Generally don't need to name all arguments mean(x = c(NA, 1:9), na.rm = T) # Unusual orders best avoided, but # illustrate the principle mean(na.rm = T, c(NA, 1:9)) mean(na = T, c(NA, 1:9)) Monday, 13 September 2010
  • 12. # Overkill qplot(x = price, y = carat, data = diamonds) # Don't need to supply defaults mean(c(NA, 1:9), na.rm = F) # Need to remember too much about mean mean(c(NA, 1:9), , T) # Don't abbreviate too much! mean(c(NA, 1:9), n = T) Monday, 13 September 2010
  • 13. f <- function(a = 1, abcd = 1, abdd = 1) { print(a) print(abcd) print(abdd) } f(a = 5) f(ab = 5) f(abc = 5) Monday, 13 September 2010
  • 14. Your turn Write a function to calculate the variance of a vector. Make sure it has a na.rm argument. Write the function in your text editor, then copy into R. Monday, 13 September 2010
  • 15. Strategy Always want to start simple: start with test values and get the body of the function working first. Check each step as you go. Don’t try and do too much at once! Create the function once everything works. Monday, 13 September 2010
  • 16. x <- 1:10 sum((x - mean(x)) ^ 2) / (length(x) - 1) var <- function(x) sum((x - mean(x)) ^ 2) / (length(x) - 1) x <- c(1:10, NA) var(x) na.rm <- TRUE if (na.rm) { x <- x[!is.na(x)] } var <- function(x, na.rm = F) { if (na.rm) { x <- x[!is.na(x)] } sum((x - mean(x)) ^ 2) / (length(x) - 1) } Monday, 13 September 2010
  • 17. Testing Always a good idea to test your code. We have a prebuilt set of test cases: the prize column in slots.csv So for each row in slots.csv, we need to calculate the prize and compare it to the actual. (Hopefully they will be same!) Monday, 13 September 2010
  • 18. For loops print(1) print(2) print(3) for(value in 1:10) print(4) { print(5) print(value) print(6) } print(7) print(8) print(9) print(10) Monday, 13 September 2010
  • 19. For loops cuts <- levels(diamonds$cut) for(cut in cuts) { selected <- diamonds$price[diamonds$cut == cut] print(cut) print(mean(selected)) } # Have to do something with output! Monday, 13 September 2010
  • 20. # Common pattern: create object for output, # then fill with results cuts <- levels(diamonds$cut) means <- rep(NA, length(cuts)) for(i in seq_along(cuts)) { sub <- diamonds[diamonds$cut == cuts[i], ] means[i] <- mean(sub$price) } # We will learn more sophisticated ways to do this # later on, but this is the most explicit Monday, 13 September 2010
  • 21. # Common pattern: create object for output, # then fill with results cuts <- levels(diamonds$cut) means <- rep(NA, length(cuts)) for(i in seq_along(cuts)) { Why use i and not cut? sub <- diamonds[diamonds$cut == cuts[i], ] means[i] <- mean(sub$price) } # We will learn more sophisticated ways to do this # later on, but this is the most explicit Monday, 13 September 2010
  • 22. seq_len(5) seq_len(10) n <- 10 seq_len(10) seq_along(1:10) seq_along(1:10 * 2) Monday, 13 September 2010
  • 23. Your turn For each diamond colour, calculate the median price and carat size Monday, 13 September 2010
  • 24. colours <- levels(diamonds$color) n <- length(colours) mprice <- rep(NA, n) mcarat <- rep(NA, n) for(i in seq_len(n)) { set <- diamonds[diamonds$color == colours[i], ] mprice[i] <- median(set$price) mcarat[i] <- median(set$carat) } results <- data.frame(colours, mprice, mcarat) Monday, 13 September 2010
  • 25. Back to slots... For each row, calculate the prize and save it, then compare calculated prize to actual prize Question: given a row, how can we extract the slots in the right form for the function? Monday, 13 September 2010
  • 26. slots <- read.csv("slots.csv") i <- 334 slots[i, ] slots[i, 1:3] str(slots[i, 1:3]) as.character(slots[i, 1:3]) c(as.character(slots[i, 1]), as.character(slots[i, 2]), as.character(slots[i, 3])) slots <- read.csv("slots.csv", stringsAsFactors = F) str(slots[i, 1:3]) as.character(slots[i, 1:3]) calculate_prize(as.character(slots[i, 1:3])) Monday, 13 September 2010
  • 27. # Create space to put the results slots$check <- NA # For each row, calculate the prize for(i in seq_len(nrow(slots))) { w <- as.character(slots[i, 1:3]) slots$check[i] <- calculate_prize(w) } # Check with known answers subset(slots, prize != prize_c) # Uh oh! Monday, 13 September 2010
  • 28. # Create space to put the results slots$check <- NA # For each row, calculate the prize for(i in seq_len(nrow(slots))) { w <- as.character(slots[i, 1:3]) slots$check[i] <- calculate_prize(w) } # Check with known answers subset(slots, prize != prize_c) # Uh oh! What is the problem? Think about the most general case Monday, 13 September 2010
  • 29. DD DD DD 800 windows <- c("DD", "C", "C") 7 7 7 80 # How can we calculate the BBB BBB BBB 40 # payoff? BB BB BB 25 B B B 10 C C C 10 Any bar Any bar Any bar 5 C C * 5 C * C 5 C * * 2 DD doubles any winning * C * 2 combination. Two DD * * C 2 quadruples. DD is wild Monday, 13 September 2010
  • 30. Homework What did we miss? Find out the problem with our scoring function and fix it. Monday, 13 September 2010