Error in code from study book

Hi, I am trying to the run code on RStudio Version 1.1.463, R version 3.5.3; form the study book about R (2014), and I get an error:
Error: unexpected symbol in:
"for (i in 1:Nboot) { boots[i] <- mean(sample(data, replace = T))}
CI <- quantile(boots, probs = c(0.025, 0.975)) return"

> boot_np <- function(data , Nboot=5000) { boots <- numeric(Nboot)
+ for (i in 1:Nboot) { boots[i] <- mean(sample(data, replace = T))}
+ CI <- quantile(boots, probs = c(0.025, 0.975)) return(c(m = mean(data), CI))}

Thank you.

Hi!

You're facing this error because R is unable to detect return(c(m = mean(data), CI)) part. It should be placed in a new line. Alternatively, you can add a ; before it.

Hope this helps.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.