I am trying to build a function that takes 3 arguments, a vector, whether to display or not a graph, and if yes, the type of graph. Unfortunately, i get an error and don't understand why. (This is for a class but i already validated the points through reasoning, i just want to progress on my code...)
my_function <- function(x, display = FALSE, type) {
if (display = TRUE & type = "hist") {
hist(x)
} if (display = TRUE & type = "plot") {
plot(x)
} else {
summary(x)
}
}
I get multiples: Error: unexpected '}' in " }"