I am new to R. I have an error message:
! Assigned data
c(analysis$"Net Present Value", analysis$"Internal Rate of Return")
must be compatible with row subscripti
.
when I try to run this function:
function(nsim = 1000, seed = 123, ...){
output_simple <- tibble('Net Present Value' = numeric(nsim),
'Internal Rate of Return' = numeric(nsim))
output_complex_l <- list()
set.seed(seed)
for(i in 1:nsim){
analysis <- cba_single(...)
output_simple[i, ] <- c(analysis$'Net Present Value', analysis$'Internal Rate of Return')
tmp <- analysis$time_series_output
tmp$id <- i
output_complex_l[[i, ]] <- tmp # was [i]
}
output_complex <- do.call(rbind, output_complex_l) %>%
gather(variable, value, -id, -year) %>%
group_by(variable, year) %>%
summarise(mid = mean(value),
lower = quantile(value, 0.1),
upper = quantile(value, 0.9))
return(list(
output_simple = output_simple,
output_complex = output_complex)
)
}
Where:
net_present_value(discount = 7, cost = costs, benefit = benefits)
Could somebody guide me as to where I need to start looking to solve this please?