> sum(results == t$survived) [1] 454 > results <- pr_df( pr1, t ) > sum(results == t$survived) [1] 582 > results <- pr_df( pr0, t ) > sum(results == t$survived) [1] 454 > ?scan Warning message: Display list redraw incomplete Error: invalid graphics state Error: invalid graphics state > x <- scan(1) Error in scan(1) : 'file' must be a character string or connection > x <- scan() 1: 54 2: 53 3: > x [1] 42 > x [1] 42 > x <- scan(n=1) 1: 54 Read 1 item > x [1] 54 Warning message: Display list redraw incomplete Error: invalid graphics state Error: invalid graphics state > MH <- function() + { + cat("Welcome Choose a curtain!\n") + x <- scan(n=1) + cat("You chose", x) + } > MH() Welcome Choose a curtain! 1: 2 Read 1 item You chose 2 > MH <- function() + { + cat("Welcome Choose a curtain!\n") + x <- scan(n=1) + cat("You chose", x) + prize = sample(1:3,1) + cat("The prize is behind",prize) + if (prize == x) { + g = prize+1 + if (prize+1 > 3) { g = 1 } + } + cat("Aha! It's good you didn't choose curtain",g"\n") Error: unexpected string constant in: " } cat("Aha! It's good you didn't choose curtain",g"\n"" > cat("Do you want to switch (1) or stay (2)?\n") Do you want to switch (1) or stay (2)? > sors = scan(n=1) 1: cat("You chose",sors) Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got 'cat("You' > } Error: unexpected '}' in "}" > MH <- function() + { + cat("Welcome Choose a curtain!\n") + x <- scan(n=1) + cat("You chose", x) + prize = sample(1:3,1) + cat("The prize is behind",prize) + if (prize == x) { + g = prize+1 + if (prize+1 > 3) { g = 1 } + } + cat("Aha! It's good you didn't choose curtain",g,"\n") + cat("Do you want to switch (1) or stay (2)?\n") + sors <- scan(n=1) + cat("You chose",sors) + } > MH() Welcome Choose a curtain! 1: 2 Read 1 item You chose 2The prize is behind 1 Error in cat("Aha! It's good you didn't choose curtain", g, "\n") : object 'g' not found > MH <- function() + { + cat("Welcome Choose a curtain!\n") + x <- scan(n=1) + cat("You chose", x) + prize = sample(1:3,1) + cat("The prize is behind",prize) + g = 6-x-prize + if (prize == x) { + g = prize+1 + if (prize+1 > 3) { g = 1 } + } + cat("Aha! It's good you didn't choose curtain",g,"\n") + cat("Do you want to switch (1) or stay (2)?\n") + sors <- scan(n=1) + cat("You chose",sors) + } > MH() Welcome Choose a curtain! 1: 2 Read 1 item You chose 2The prize is behind 3Aha! It's good you didn't choose curtain 1 Do you want to switch (1) or stay (2)? 1: 1 Read 1 item You chose 1 > MH <- function() + { + cat("Welcome Choose a curtain!\n") + x <- scan(n=1) + cat("You chose", x,"\n") + prize = sample(1:3,1) + cat("The prize is behind",prize,"\n") + g = 6-x-prize # trick to getting garbage curtain + if (prize == x) { + g = prize+1 + if (prize+1 > 3) { g = 1 } + } + cat("Aha! It's good you didn't choose curtain",g,"\n") + cat("Do you want to switch (1) or stay (2)?\n") + sors <- scan(n=1) + cat("You chose",sors) + } > MH() Welcome Choose a curtain! 1: 1 Read 1 item You chose 1 The prize is behind 1 Aha! It's good you didn't choose curtain 2 Do you want to switch (1) or stay (2)? 1: 2 Read 1 item You chose 2 > MH <- function() + { + cat("Welcome Choose a curtain!\n") + x <- scan(n=1) + #cat("You chose", x,"\n") + prize = sample(1:3,1) + #cat("The prize is behind",prize,"\n") + g = 6-x-prize # trick to getting garbage curtain + if (prize == x) { + g = prize+1 + if (prize+1 > 3) { g = 1 } + } + cat("Aha! It's good you didn't choose curtain",g,"\n") + cat("Do you want to switch (1) or stay (2)?\n") + sors <- scan(n=1) + #cat("You chose",sors) + if (sors == 1 & x==prize) { + cat("You LOSE!") + return(0) + } + else if (sors == 2 & x != prize) { + cat("You LOSE!") + return(0) + } + else { + cat("You WIN!\n") + return(1) + } + } > MH() Welcome Choose a curtain! 1: 3 Read 1 item Aha! It's good you didn't choose curtain 1 Do you want to switch (1) or stay (2)? 1: 1 Read 1 item You LOSE![1] 0 > MH() Welcome Choose a curtain! 1: 3 Read 1 item Aha! It's good you didn't choose curtain 1 Do you want to switch (1) or stay (2)? 1: 1 Read 1 item You WIN! [1] 1 > MH() Welcome Choose a curtain! 1: 3 Read 1 item Aha! It's good you didn't choose curtain 2 Do you want to switch (1) or stay (2)? 1: 1 Read 1 item You WIN! [1] 1 > 3%2 Error: unexpected input in "3%2" > ?mod No documentation for ‘mod’ in specified packages and libraries: you could try ‘??mod’ > > ?modulo No documentation for ‘modulo’ in specified packages and libraries: you could try ‘??modulo’ > 3%%2 [1] 1 Warning message: Display list redraw incomplete Error: invalid graphics state Error: invalid graphics state > u <- scan(n=1) 1: "hi" 1: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got '"hi"' > u <- scan(what = " ") 1: "hi" 2: > u Error: object 'u' not found > u <- scan(what = " ", n = 1) 1: "hi" Read 1 item > "switch" == "switch" [1] TRUE > "switch" == "swith" [1] FALSE > source('~/.active-rstudio-document', echo=TRUE) > # single-line comment > " + multi-line comment! + + Below is a function that runs ONE trial of + the Monty Hall three-curtain game from the + show ..." ... [TRUNCATED] [1] "\nmulti-line comment!\n\nBelow is a function that runs ONE trial of\nthe Monty Hall three-curtain game from the\nshow 'Let's Make a Deal'\n" > MH <- function() + { + # get the user's curtain into user + cat("Welcome! Choose a curtain!\n") + user <- scan(n=1) # this is how to get one .... [TRUNCATED] > guesser <- function(hidden,verbose=T) + { + g <- -1 + i <- 0 + repeat { + g <- sample(1:100,1) + i <- i+1 + if (verbose == T) {cat .... [TRUNCATED] > # Titanic problem starter file... > # Be sure to comment each function using # or " " > > " + Here is an example of multi-line quote-based 'com ..." ... [TRUNCATED] [1] "\n Here is an example of multi-line quote-based 'comments' ...\n\n pr0(obs) takes in one observation (obs)\n and outputs whether or not that passenger would have\n survived by our model...\n\n In the case of pr0, the prediction is that every\n passenger perishes (0)\n" > pr0 <- function(obs) { + return(0) + } > # Here is an example of #-style (single-line) comments > # > # pr1(obs) is a function that takes in one observation (obs) > # and outputs whether or .... [TRUNCATED] > " + pr_df(FUN,df) takes in + FUN: a function that predicts for one observation, such as + pr0 or pr1 + df: a dataframe with po ..." ... [TRUNCATED] [1] "\n pr_df(FUN,df) takes in\n FUN: a function that predicts for one observation, such as\n pr0 or pr1\n df: a dataframe with possible many observations to test\n\n pr_df returns a vector of predictions, one per row in the\n dataframe df\n" > pr_df <- function(FUN,df) { + NUM_ROWS <- nrow(df) + #cat("NUM_ROWS is", NUM_ROWS) + predictions = vector(mode="numeric",length=NUM_ROWS) + .... [TRUNCATED] > sum(t2$survived == pr_df(pr0,t2)) [1] 3 > MH() Welcome! Choose a curtain! 1: 2 Read 1 item Aha! It's good you didn't choose curtain 3 Do you want to switch or stay? You may type "switch" or "stay": 1: "switch" Read 1 item You LOSE![1] 0 > source('C:/Users/Owner/Desktop/titanic.R', echo=TRUE) > # single-line comment > " + multi-line comment! + + Below is a function that runs ONE trial of + the Monty Hall three-curtain game from the + show ..." ... [TRUNCATED] [1] "\nmulti-line comment!\n\nBelow is a function that runs ONE trial of\nthe Monty Hall three-curtain game from the\nshow 'Let's Make a Deal'\n" > MH <- function() + { + # get the user's curtain into user + cat("Welcome! Choose a curtain!\n") + user <- scan(n=1) # this is how to get one .... [TRUNCATED] > guesser <- function(hidden,verbose=T) + { + g <- -1 + i <- 0 + repeat { + g <- sample(1:100,1) + i <- i+1 + if (verbose == T) {cat .... [TRUNCATED] > # Titanic problem starter file... > # Be sure to comment each function using # or " " > > " + Here is an example of multi-line quote-based 'com ..." ... [TRUNCATED] [1] "\n Here is an example of multi-line quote-based 'comments' ...\n\n pr0(obs) takes in one observation (obs)\n and outputs whether or not that passenger would have\n survived by our model...\n\n In the case of pr0, the prediction is that every\n passenger perishes (0)\n" > pr0 <- function(obs) { + return(0) + } > # Here is an example of #-style (single-line) comments > # > # pr1(obs) is a function that takes in one observation (obs) > # and outputs whether or .... [TRUNCATED] > " + pr_df(FUN,df) takes in + FUN: a function that predicts for one observation, such as + pr0 or pr1 + df: a dataframe with po ..." ... [TRUNCATED] [1] "\n pr_df(FUN,df) takes in\n FUN: a function that predicts for one observation, such as\n pr0 or pr1\n df: a dataframe with possible many observations to test\n\n pr_df returns a vector of predictions, one per row in the\n dataframe df\n" > pr_df <- function(FUN,df) { + NUM_ROWS <- nrow(df) + #cat("NUM_ROWS is", NUM_ROWS) + predictions = vector(mode="numeric",length=NUM_ROWS) + .... [TRUNCATED] > sum(t2$survived == pr_df(pr0,t2)) [1] 3 > MH() Welcome! Choose a curtain! 1: 3 Read 1 item Aside: [[ The prize is behind 3 ]] Aha! It's good you didn't choose curtain 1 Because that had a consolation prize... Do you want to switch or stay? You may type "switch" or "stay": 1: "stay" Read 1 item You WIN! [1] 1 > source('C:/Users/Owner/Desktop/titanic.R', echo=TRUE) > # single-line comment > " + multi-line comment! + + Below is a function that runs ONE trial of + the Monty Hall three-curtain game from the + show ..." ... [TRUNCATED] [1] "\nmulti-line comment!\n\nBelow is a function that runs ONE trial of\nthe Monty Hall three-curtain game from the\nshow 'Let's Make a Deal'\n" > MH <- function() + { + # get the user's curtain into user + cat("Welcome! Choose a curtain!\n") + user <- scan(n=1) # this is how to get one .... [TRUNCATED] > guesser <- function(hidden,verbose=T) + { + g <- -1 + i <- 0 + repeat { + g <- sample(1:100,1) + i <- i+1 + if (verbose == T) {cat .... [TRUNCATED] > # Titanic problem starter file... > # Be sure to comment each function using # or " " > > " + Here is an example of multi-line quote-based 'com ..." ... [TRUNCATED] [1] "\n Here is an example of multi-line quote-based 'comments' ...\n\n pr0(obs) takes in one observation (obs)\n and outputs whether or not that passenger would have\n survived by our model...\n\n In the case of pr0, the prediction is that every\n passenger perishes (0)\n" > pr0 <- function(obs) { + return(0) + } > # Here is an example of #-style (single-line) comments > # > # pr1(obs) is a function that takes in one observation (obs) > # and outputs whether or .... [TRUNCATED] > " + pr_df(FUN,df) takes in + FUN: a function that predicts for one observation, such as + pr0 or pr1 + df: a dataframe with po ..." ... [TRUNCATED] [1] "\n pr_df(FUN,df) takes in\n FUN: a function that predicts for one observation, such as\n pr0 or pr1\n df: a dataframe with possible many observations to test\n\n pr_df returns a vector of predictions, one per row in the\n dataframe df\n" > pr_df <- function(FUN,df) { + NUM_ROWS <- nrow(df) + #cat("NUM_ROWS is", NUM_ROWS) + predictions = vector(mode="numeric",length=NUM_ROWS) + .... [TRUNCATED] > sum(t2$survived == pr_df(pr0,t2)) [1] 3 > MH() Welcome! Choose a curtain! 1: 1 Read 1 item Aside: [[ The prize is behind 1 ]] Aha! It's good you didn't choose curtain 2 Because that had a consolation prize... Do you want to switch or stay? You may type "switch" or "stay": 1: "stay" Read 1 item You WIN! [1] 1 > MH() Welcome! Choose a curtain! 1: 2 Read 1 item Aside: [[ The prize is behind 2 ]] Aha! It's good you didn't choose curtain 3 Because that had a consolation prize... Do you want to switch or stay? You may type "switch" or "stay": 1: "switch" Read 1 item You LOSE![1] 0