Commit 53f8520e authored by linushof's avatar linushof
Browse files

Add description for function

parent 1e63c424
# Functions for generating cumulative sums and and means
## cumsum2() and cummean2() are extensions of the base functions including a na.rm-argument.
## If na.rm = TRUE, the lagging cumulative value is used for the position of the missing element.
# cumsum2()
cumsum2 <- function(x, na.rm = FALSE) {
output <- vector("double", length(x))
for (i in seq_along(x)) {
if(sum(is.na(x[1:i])) == length(x[1:i])) {
if(sum(is.na(x[1:i])) == length(x[1:i])) { # return NA if all lagging values are NA
output[[i]] <- NA
} else {
output[[i]] <- sum(x[1:i], na.rm = na.rm)
......@@ -10,7 +14,6 @@ cumsum2 <- function(x, na.rm = FALSE) {
}
output
}
# cummean2()
cummean2 <- function(x, na.rm = FALSE) {
output <- vector("double", length(x))
......
pacman::p_load(tidyverse)
# call function for generating gambles
source("R/fun_generate_gambles.R")
source("R/fun_generate_gambles.R") # call function for generating 2-outcome gambles
# generate 10,000 safe-risky gambles
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment