R/commonValVec.R

Defines functions commonValVec

Documented in commonValVec

#'commonValVec
#' @param vec1 a vector to be compared 
#' @param vec2 a vector to be compared
#' @return commonValVec returns a vector containing the common values present in both vectors. If the common values are all numeric then the output vector is of class numeric. If at least one of the common values is a character, then the output vector is of class character.
#' @description commonValVec takes as input two vectors (\code{vec1} and \code{vec2}) and returns a vector containing the common values present in both vectors. 
#' @examples
#' commonValVec(c(1,2,"a"),c(2,"a",3,4,5))
#' commonValVec(c(1,2,"dog",10,"apple"),c(11,22,"dog",2,"orange"))
#' commonValVec(c(1,2,4,8),c(8,22,2,"dog"))
#' @export
commonValVec<-function(vec1,vec2)
{
  commonValVector<-vec1[c(which(!is.na(match(vec1,vec2))))]

  return(commonValVector)
}
lwTools/agriTrf documentation built on March 26, 2020, 12:09 a.m.