Please use R code Often you will need to recode values of a dataset. For example, if you have a vectors of elapsed time, you
Please use R code
Often you will need to recode values of a dataset. For example, if you have a vectors of elapsed time, you may want to convert any nonsense values (like anything below 0, time can't be negative) to the special value `NA`.
1. Write a function called `recode.times()` that takes one argument: `x`, a vector of times (and we'll assume the user will do so correctly, don't worry about error checking yet). The function should look at the values of `x`, change any values of `x` that are below 0 to `NA`, and then return the edited vector. Test the function on the vector `test_x <- c(18, -6, 107, 230)` 2. Add in code that checks whether the input argument is numeric, and returns "This function is for numeric vectors" if the input isn't numeric. Test the new version of the function on the vector `test_y <- c("vector", "of", "strings")`
```{r}
test_x <- c(18, -6, 107, 230)
```
```{r}
test_y <- c("a", "vector", "of", "strings")
```
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started