Assignment 11: Debugging and defensive programming in R
Assignment 11: Debugging and defensive programming in R This week was interesting because we were given the code we needed and were tasked with fixing the error(/s) that was(/were) present. First though we needed to run the program so that the system itself could aid in our diagnosis of the issue which can be seen below: Here we can see that with the addition of the second & sign made the logic of the program attempt to only evaluate the first element of each vector, which is not what is needed. Further, && is usually used with if statements or while loops whereas the single & is used for vector or matrix operations. The correction with the single & results in the program checking each row independently, fixing the previous logical error, seen below: The above is the corrected code with the proper number of ampersands. Unlike the first set of code, we can see an output instead of an error message, and each row has...