Your first for loop
To make sure you fully understand what you've just done, let's try running a smaller version.
To help you remember the syntax, initialization was done with the rep()
function: rep(NA, n)
.
And this is how you do a for loop:
for (i in 1:n) {
...
}
This exercise is part of the course
Data Analysis and Statistical Inference
Exercise instructions
- Initialize a vector of 100
NA
s calledsample_means_small
. - Run a loop for 100 times that takes a sample of size 50 from
area
and stores the samplemean
insample_means_small
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# The ames data frame and area and price objects are already loaded into the workspace
# Initialize the vector to store the means in:
sample_means_small <-
# Run your for loop:
for (___) {
}
# Print the result:
sample_means_small