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

    • Data Generating Process (DGP)

      Data Generating Process (DGP) The Data Generating Process (DGP) refers to the underlying mechanism—real or hypothetical—that produces the data we observe. A DGP specifies how variables are related, how randomness enters the system, and how observed ...
    • What are the boxes and whiskers in a boxplot?

      What are the boxes and whiskers in a boxplot? We use boxplots to show the distribution of data mainly through four quartiles (Q1, Q2, Q3, Q4). The boxplot has two whiskers (Q1, Q4), two smaller boxes (Q2, Q3) and a larger central box (Q2, Median, Q3) ...
    • recode()

      The recode() function can be used to rename any of the values of a variable. Example: # recode the variable `Year` and save it is a new column in the data frame Fingers$Year_recode <- recode(Fingers$Year, "1" = "First", "2" = "Second", "3" = "Third", ...
    • Using the R Sandbox

      The R Sandbox The R Sandbox is a separate R window you can use to experiment with R code and play around with ideas from the course. It comes pre-loaded with the base R packages and all of the packages and datasets we reference in the textbook. ...
    • 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 ...