Question: In R, write a simple function called threshold_five that takes a single numeric vector x as input. Within this function, use sapply to construct a
In R, write a simple function called threshold_five that takes a single numeric vector x as input. Within this function, use sapply to construct a new vector that corresponds to the elements of x and, for each x[i], is zero if x[i] < 5, and one else. For example, you should get the following:
threshold_five(c(1,3,6,10,4)) 0, 0, 1, 1, 0
You must use sapply (in combination with a simple function you define, anonymously or not) to accomplish this task.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
