0

I am a uni student doing stats, currently looking at creating functions in r. I really struggle with functions and am stuck on certain one I am having to create. I was wondering if someone could help me with this or lead me in the right direction.

I'm writing a function "BCa" that creates a bootstrap interval. The first argument I have to write is meant to be the statistic of interest to be bootstrapped when executed on a vector of data

For example, if I were to put 'BCa(stat=mean,...' I'd be bootstrapping the sample mean when using 'stat(...' inside your function, or 'BCa(stat=quantile,...' I'd be bootstrapping the certain quantile when using 'stat(...'

I just don't quite know how to make this argument completely take over what another function does. I'd be very appreciative if someone could help.

Tom Gold
  • 1
  • 1
  • If your question is just how to pass a function as an argument... you just do it and it works. `foo <- function(fun, data) {fun(data)}` will work and you could use `foo(fun = mean, data = 1:10)` or `foo(fun = sum, data = c(2, 3, 4))` – Gregor Thomas Oct 01 '22 at 03:03
  • @GregorThomas, sorry I never meant for someone to write all the code for me, I've been trying to but just have not been able to figure it out. Thank you for your reply though and for the code to try, I really appreciate it. – Tom Gold Oct 02 '22 at 21:01
  • Sorry for the misunderstanding. Try to make your questions focused and specific, and also show what you tried. That will make it easier to help and clearer--as well as more clearly in-scope. – Gregor Thomas Oct 03 '22 at 00:02

0 Answers0