This is a gist I made in GitHub for Module 2's assignment. Here it is-
The function provided in the assignment module would work for all numerical type of data. However, function would likely to yield an error or wrong result if there is "NA" in the vector. Reason for that is, R's premade sum() function doesn't handle "NA" out of the box. You have to mention sum(x, na.rm=TRUE). This way sum() function will skip over "NA" values. But, then lenght() function would count the length including the "NA". So this will result in a wrong result {Logic Error}.
To fix an logic error associated with "NA" in a vector I've added a line #5 above, which removes the "NA" and updating the vector again so both sum() and length() function work as they should.
Thanks,
Mihir
The function provided in the assignment module would work for all numerical type of data. However, function would likely to yield an error or wrong result if there is "NA" in the vector. Reason for that is, R's premade sum() function doesn't handle "NA" out of the box. You have to mention sum(x, na.rm=TRUE). This way sum() function will skip over "NA" values. But, then lenght() function would count the length including the "NA". So this will result in a wrong result {Logic Error}.
To fix an logic error associated with "NA" in a vector I've added a line #5 above, which removes the "NA" and updating the vector again so both sum() and length() function work as they should.
Thanks,
Mihir
Comments
Post a Comment