Functions

Author

Jeffrey R. Stevens

Published

March 27, 2023

  1. Write a function called mystring that takes a vector as an argument and returns the first three characters from the string. Test it on words[1:10].
# >
  1. Add an argument to mystring() that allows the user to control how many of the first characters should be returned. Test it on words[1:10] with 5 characters.
# >
  1. Set the default number of characters returned by mystring() to be 3 and test that the default works and that you can override the default.
# >
  1. Add a step that checks whether the inputted vector is a character string. If it is, continue to return the truncated strings. If the vector is not a character string, use the stop() function to stop the computation and return a message to the console telling the user that the vector was not a character vector. Test your function with a character vector, a numeric vector, and a logical vector.
# >
  1. Create a function called parse_my_vector that does the following:
# >
  1. Check the following with parse_my_vector():
# >