R provides lots of tools to manipulate vectors. In this package, we will implement several vector manipulating functions, including
mlist by using the R console command:
devtools::install_github("UBC-MDS/mlist_R", build_opts = c("--no-resave-data", "--no-manual"))
To load the
mlist library by using the R console command:
After loading the mlist package, you can call the functions.
covrby using the R console command:
covrlibrary by using the R console command:
The result suggest 100% test coverage:
|1|binary_search(x, lst)|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 index in
lst.|x: numeric, lst: sorted vector of numerics|binary_search(4, c(1,2,3,4,5,6))|
|2|flatten_dataframe_prime(dataframe)|This function takes a dataframe contains multiple vectors and returns a flat vector that contains only prime numbers.|dataframe: a dataframe contains multiple vectors of numerics|flatten_dataframe_prime(data.frame(c(2, 3, 4), c(5, 6, 7), c(8, 9, 10)))|
|3|find_prime(x)| Return the largest prime number for a given list.|x : a vector of numerics|find_prime(c(0,1,2,3,4,5))|
binary_search(x, lst): In the R environment, there are two functions have the similar functionality as binary_search. The first one is findintervals, which returns the position indices of a numeric value in a numeric vector. Another one is the operator
%in% which is used to identify if an element belongs to a vector. Comparing with them, the binary_search function is able to return a list contains whether
x is in the
x position indices in
flatten_dataframe_prime(dataframe): There is no function that returns the prime numbers in a dataframe.
find_prime(list): There is no function that find the largest prime for a given vector, but there is similar function in R environment, such as isprime, that test if a number is a prime or not.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.