Replace Loops in R function

Posted by David Hicks on Stack Overflow See other posts from Stack Overflow or by David Hicks
Published on 2010-05-10T03:20:52Z Indexed on 2010/05/10 3:28 UTC
Read the original article Hit count: 402

Filed under:
|
|

Hi, I'm new to R, and I'm having trouble figuring out how to replace the FOR loop in the function below. The function estimates a population mean. Any help at all would be much appreciated. Thank you!

myFunc<- function(){

myFRAME <- read.csv(file="2008short.csv",head=TRUE,sep=",")

meanTotal <- 0

for(i in 1:100) {

mySample <- sample(myFRAME$TaxiIn, 100, replace = TRUE)

tempMean <- mean(mySample)

meanTotal <- meanTotal + tempMean

}

cat("Estimated Mean: ", meanTotal/100, "\n") #print result

}

© Stack Overflow or respective owner

Related posts about r

    Related posts about loops