do()*

do()*

The do()* function runs one or more lines of code the number of times specified inside the parentheses and returns the results as a data frame.

Example 1:

# take a random sample (n=10) of a variable, with replacement,

# and calculate the standard deviation of the 10 numbers, 3 times

do(3) * sd(resample(Fingers$Thumb, 10))


Example output (although actual values may vary due to random sampling variation):

Example 2:

# get the means of 10,000 random samples (n=157) with replacement

# and save in a new data frame
# use head() to view the first 6 rows

new_data <- do(10000) * mean(resample(Fingers$Thumb, 157)) 

head(new_data)

Example output (although actual values may vary due to random sampling variation):



    • Related Articles

    • Appendix of Data Frames Used in Course Textbook

      All data frames listed below are automatically preloaded when you run library(coursekata). Link to full repository of R documentation: https://www.rdocumentation.org/ Data Frame Name and Link to R Documentation Ames BikeCommute FatMice18 Fingers ...
    • Statement on Sex and Gender

      Many people use sex and gender interchangeably, but in truth, they’re distinct concepts.  Sex is a classification based on biological characteristics, including DNA and anatomy.  Gender refers to the socially constructed roles, behaviors, ...
    • Page Won't Load or Button Doesn't Work

      Page Won't Load / Button Doesn't Work The problem:  You click on a page in CourseKata and the content won't load (page won't load) You click on a button in CourseKata and nothing happens (button doesn't work) What to try:  Note: the suggestions below ...
    • Links Not Working

      If a link isn’t working, here are a few things you can try: Open link in a new tab or window Right click the link (or CTRL-click if you are using a Mac) Click Open Link in New Tab or Open Link in New Window     Update your browser  Make sure you are ...
    • Printing Pages of the Book

      If you need to print pages of the book, you may find that printing them from Chrome results in oddly-formatted pages.  You will get better-formatted pages if you print using either Safari or Firefox as your browser. If using Safari, go the the Safari ...