Question: In R Programmer requirements all answers Required data sets Github 1. large vector.RData 2. large list.RData To access this data in your project, please create

In R Programmer requirements

In R Programmer requirements all answers Required data sets Github 1. large

vector.RData 2. large list.RData To access this data in your project, please

all answers

Required data sets Github 1. large vector.RData 2. large list.RData To access this data in your project, please create an upstream remote to this repository from your forked version of the repositery, fetch, and then merge it with your own. For a more detailed explanation of how to do this, please see the instructions for Module- 5 exercises on Canvas. Alternatively, you may also download the data sets from the Github repository website. Instructions R supports many different ways to iterate through data: apply, for, and while (as well as others like repeat and map). Loops iterate over vectors and lists to repeatedly fun code with changing options. Changing options in different iterations is done using Booleanstatements(if, else, and ifelse) and comparison operators (,>,=,E,s=, and ). Here we practice iterating and controlling flow in simple, or maybe not so simple, examples. There are many techniques available to iterate and thecchoice depends on the data used and the goal fofcomputation. We will compare iterative techniques in terms of utilization, readability, and computation time. The package tictoc is used to measure computation time. Install tictoc using the command devtools: install github("collectivemedia/tictoc") in your console. Remember, downloading packages only need to be done once and do notneed to be included in the analysis report. Part 1: Iterations Question 1 - Creating For and While loops Questions 1 uses the large vector data set. 1A Use a while loop to assign a new variable; mean while, as the mean of large vector. Use print to display this value. 1B Use a for loop to assign a new variable, mean for as the-mean of large vector. Use print to display this value 1C How are these methods similar and how might vectorized functions be-supecior? Question 2 - Loops vs vectorized functions Questions 2 uses the large vector dataset. For Question 2, parts A and B, we willnormalize eaebelementin largevector by the total sum of large vector using for loops and the vectorized function -mean. Algorithms for each-method should be encapsulated within-tic and toc to compare computation timeas shown in the example below: library ( tictoce) tic() H-starts timer After tic and toc encapsulation to show computation times for each method, show that the normalization was done correctly by summing each element in the normalized vector (they should equal one after normalization): 2A Use vectorized functions to assign a new variable, norm vectorized, using the normalization described in the questionstem. For this question, it ispermissible to use vectorized functions to verify that the normalization was done correctly. 2B Use a for loop to assign a new variable, norm loop, using the normalization described in the question stem. For this question, it IS NOT permissible to use vectorized function to calculate total sum- (use a for loop). 2C Please explain the differences between these methods in terms of implementation, readability, and computation time. Using your own experiences in the workplace (or speculation of experiences for a job you would like to have), how might these differences be significant and what impact would they have? Question 3-Apply vs loops Question 3 uses the large_list data set. Vectorized functions are allowed in this question. Algorithms for each method should be encapsulated within tic and toc to compare computation time. After tic and toc encapsulation to show computation times for each method, print the contents of eachnewly assigned list. 3A Use apply to assign a new variable, mean_list_apply, the-mean of each vector in large_list. 3B Use for loop to assign a newvariable,mean_list_for, the mean of eachvector in large_list. 3C Please explain the differences between these methods in terms of implementation, readability, and computation time. Were these differences surprising? How do you predict these differences will change if we used lists with much more elements (i.e. length ( list )>1000) ? Part 2: Control Controlling flow isimportant for manipulating data based on theicvalues. Weshow how easy R makes control and iteration by comparing theUn-R way with the R way. TheUn-Rway uses for-loops and if/ else statementswhile the R way uses proper subsettingand vectorization. Let's explore these differences. Question 4 - Doing it the Un-Rway Questions 4 uses the large_vector data set. 4A Use the Un-Rway, witha for-loop and if / else-statements, to assign anew variable, nbr_zeros_loop, as the number of zeros that are in large vector. Print the value of this variable. 4B Use the Un-R way, with a for loop and if / else statements.to assign a newvariable,smaller_vector_loop, as all the values of large vector that are not equal tozero. Vectorized functions (i.e. na.omit) are permitted but a for loop must be used to iterate through vector. Show that the sum of nbr_zeros_loop and the length_of smaller_vector_loop are equal to the length of larger_vector. Question 5 - Doing it the R-way Questions 5 uses the large_vector data set. 5A Use the R way, proper subsetting and vectorized functions, to assigna new variable, nbr_zeros, as the number of zeros that are in large_vector. Print this variable. Show that nbr_zeros and nbr_zeros_loop are equal. 5B Use the R way, proper subsetting and vectorized functions, to assign a new variable, smaller_vector, as all the values of large_vector that are notequal to zero. Show that the sum of nbr_zeros and the length of smaller-vector are equal to the length of larger_vector

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!