I'm just learning to write functions in R for the first time and I'm trying to mimic the rbinom() function in R. I've written some code but I'm not sure if it is repeating what rbinom() does. Also how do I return multiple observations in one go, like rbinom(). Thirdly, is there a more efficient way to create a function like this? I've used the example of n=100, p=0.1 so far
myrbinom<-function(x){
x<-runif(n)
count=0
for(i in 1:n){
if(x[i]<=p){
count=count+1
}
}
return(count)
}
p=0.1
n=100
myrbinom(x)