Description
Given the code below, provide the fix to it so error message does not appear.
> x <- c(8, 5, 9, NA)
> for(i in seq_along(x))
- + {
+ if(x[i] = 5) { cat(i, “n”) }
Error: unexpected ‘=’ in:
“{
if(x[i] =”
> }
Error: unexpected ‘}’ in “}”
Given the function below, provide the fix so error does not appear:
> printmessage <- function(x) {
+ if(x > 0)
+ print(“x is greater than zero”)
+ else
+ print(“x is less than or equal to zero”)
- + invisible(x)
+ }
But when we call:
> printmessage(NA)
Error in if (x > 0) print(“x is greater than zero”) else print(“x is less than or equal to zero”): missing value where TRUE/FALSE needed
For the submission send the corrected function in which you fix the problems above, so errors do not occur.