knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
R provides lots of tools to manipulate vectors. In this package, we will implement several vector manipulating functions, including binary_search(), flatten_dataframe_prime(), and find_prime(). The first function searches an input vector for a specified element. The other two functions deal with looking for prime numbers: flatten_dataframe_prime()
returns a vector of the prime numbers in a dataframe, and find_prime()
returns the largest prime number in a vector.
Description: Search if the value x exists in the lst, and return a vector contains: TRUE/FALSE depends on whether the x value has been found, x value, and x position indices in lst.
Input: the number x to search for and the list the search in
An error will be thrown in the following cases:
Output: a vector with the elements:
Example: binary_search(4, c(1,2,3,4,5,6))
c('TRUE','4','4')
Description: This function takes a dataframe of numbers and returns all the prime numbers in the dataframe.
Input: a dataframe of numbers The numbers must be less than or equal to 1,000.
An error will be thrown in the following cases:
Output: a vector of all the prime numbers in the dataframe The output vector is sorted ascendingly, and duplicate prime numbers are removed.
Example: flatten_dataframe_prime(data.frame(c(2, 3, 4), c(5, 6, 7), c(8, 9, 10)))
c(2, 3, 5, 7)
Description: Return the largest prime number for a given list.
Input: a vector of numerics
An error will be thrown in the following cases:
Output: the largest prime number in the input vector
Example: find_prime(c(0,1,2,3,4,5))
5
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.