Answer :
#output the new vectorreturn(z) }Calling Function:checkers(1:3) Output :## [1] 1 0 2 0 3checkers(c(1:3, NA, 6:4)) Output :## [1] 1 0 2 0 3 0 6 0 5 0 4checkers(c(TRUE, FALSE, NA)) Output :## Error in checkers(c(TRUE, FALSE, NA)): x is not a numeric vector
The solution for the given problem statement: Function Definition :
checkers <- function(x) {
# Condition to check whether the input is numeric or not
if (!is.numeric(x)) {
# If the condition is true, then the following error message will be displayed
stop("x is not a numeric vector")
}
# Store the non-NA elements of the vector in a new vector named "y"
y <- x[!is.na(x)]
# Define an empty vector named "z" to store the output values
z <- numeric(length(y)*2-1)
# Loop through the indices of "y" to fill the new vector "z"
for (i in seq_along(y)) {
z[(i*2)-1] <- y[i]
if (i != length(y)) {
z[i*2] <- 0
}
}
# Return the resulting vector "z"
return(z)
}
To know more about vector visit:
https://brainly.com/question/24256726
#SPJ11