Question
Please solve in RStudio with comments. # 1. Write a for loop that iterates over the numbers 1 to 7 and prints the cube of
Please solve in RStudio with comments.
# 1. Write a for loop that iterates over the numbers 1 to 7 and prints the cube of each number using print(). # 2. Write a for loop that iterates over the column names of the inbuilt iris dataset and print each together with the # number of characters in the column name in parenthesis. Example output: Sepal.Length (12). # Use the following functions print(), paste0() and nchar(). # 3. Write a while loop that prints out standard random normal numbers (use rnorm()) but stops (breaks) if you get a number greater than 1 # 4. Write a double for loop which prints 30 numbers (1:10, 2:11, 3:12). Those are three clusters of ten numbers each. # The first loop determines the number of clusters (3) via its length; # the second loop the numbers to be printed (1 to 10 at the beginning). Each cluster starts one number higher than the previous one # 5. Write a for loop that prints the Displacement (?disp?) of the ?mtcars? dataset. # a. This loop will only print observations of 160 or higher in ?disp?. # b. This loop will stop as soon as an observation is smaller than 160 in ?disp?. # 6. Write a while loop starting with x = 0. The loop prints all numbers up to 35 but it skips number 7. # 7. We are using the same while loop as in the last exercise. The loop prints again all numbers up to 35, # but this time it skips a whole vector of numbers: 3,9,13,19,23,29. # 8. You have an urn with balls from 1 to 100. You want to find out how often you need to draw a ball to get number 55. # This is an experiment with replacement ? you put the ball back each time you draw. # Simulate 1000 runs of the experiment to get an accurate estimation of the required draws. # 9. Get 1000 simulations of a paired dice game. # A game immediately stops if you have an initial total (2 dice) of 5,6,7,8,9. # If the first cast does not meet those 5 totals you would continue until you get either 11 or 12. # What is the average number of dice casts per game? # 10. Create a function to print class of an argument # 11. Create a function that given a data frame will print by screen the name of the column and the class of data it contains # (e.g. Variable1 is Numeric). # 12. Create a function what will return TRUE if a given integer is inside a vector. # 13. Create a function that given a vector will print the mean and the standard deviation, it will optionally also print the median. # 14. Create a function that given an integer will calculate how many divisors it has (other than 1 and itself). # Make the divisors appear by screen. # 15. Create a function that given a data frame, and a number or character will # return the data frame with the character or number changed to NA.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started