Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can someone help me with 2.6, thanks! 2. Data structures. In this question you will practice working with vectors, matrices and dataframes. 2.1. Create a
can someone help me with 2.6, thanks!
2. Data structures. In this question you will practice working with vectors, matrices and dataframes. 2.1. Create a vector x of 20 integers randomly drawn from all integers between 1 and 100. Run the command set.seed (1000) before creating x to ensure consistent perfor- mance of random number generator. Check the help for function sample() to see how to do it. 2.2. Create a 20 x 3 matrix y with 3 columns being the output of fizz(x), buzz(x) and fizzbuzz(x), correspondingly. Start with creating y as an empty (i.e. filled with NA ) matrix. You can do this by combining 3 empty 20 x 1 vectors or by using the function matrix(). Then fill in each column of y with output of functions above. Note: there should be no NA values in y after this. 2.3. Create an empty dataframe data with 20 rows and a single variable data$input . 2.4. Assign data$input the values from vector x. 2.5. Now create three more variables data$fizz , data$buzz and data$fizzbuzz as values from corresponding columns from matrix y. Make sure to use vectorized operation, not loops cycling through all the values in y. 2.6. Create yet another variable data$fbr as an output of your fbr() function applied to the values in variable data$input. If your fbr() function is not vectorized, you will need to apply fbr() to each row of data$input separately. Hint: you can supply the same argument twice to your fbr() function. 2. Data structures. In this question you will practice working with vectors, matrices and dataframes. 2.1. Create a vector x of 20 integers randomly drawn from all integers between 1 and 100. Run the command set.seed (1000) before creating x to ensure consistent perfor- mance of random number generator. Check the help for function sample() to see how to do it. 2.2. Create a 20 x 3 matrix y with 3 columns being the output of fizz(x), buzz(x) and fizzbuzz(x), correspondingly. Start with creating y as an empty (i.e. filled with NA ) matrix. You can do this by combining 3 empty 20 x 1 vectors or by using the function matrix(). Then fill in each column of y with output of functions above. Note: there should be no NA values in y after this. 2.3. Create an empty dataframe data with 20 rows and a single variable data$input . 2.4. Assign data$input the values from vector x. 2.5. Now create three more variables data$fizz , data$buzz and data$fizzbuzz as values from corresponding columns from matrix y. Make sure to use vectorized operation, not loops cycling through all the values in y. 2.6. Create yet another variable data$fbr as an output of your fbr() function applied to the values in variable data$input. If your fbr() function is not vectorized, you will need to apply fbr() to each row of data$input separately. Hint: you can supply the same argument twice to your fbr() functionStep 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