#' Compare two numeric vectors for greatness
#'
#' In this function a numeric vector supersedes (comes after) another numeric vector if the left-most differeing number between the two vectors is higher in value.
#'
#' Function starts by comparing the first element from each sequence. If they are equal, it goes on to the next element, and so on, until it finds elements that differ.
#' Subsequent elements are not considered (even if they are really big).
#' For example c(0,1,200000) is NOT greater than c(0,3,4)
#'
#' @param lst List of length 2 containing the vectors to be compared. Vectors must be of the same length.
#' @return 1 if first element is greater, 2 if second element is greater.
#' @export
compareNumericVectors = function(lst){
stopifnot(length(lst)==2 & length(lst[[1]])==length(lst[[2]]))
firstVector = lst[[1]]
secondVector = lst[[2]]
vectorSize = length(firstVector)
for(i in 1:vectorSize){
if(firstVector[i] == secondVector[i]){
next
}
else{
if(firstVector[i] > secondVector[i]){
return(1)
}
else{
return(2)
}
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.