R/loc.row.R

Defines functions loc.row

Documented in loc.row

#'loc.row
#' @param dfCol a column of a data.frame object. Note that this is not a character string but the column itself (refer to examples).
#' @param vec a vector (numeric/character) indicating the elements which are to be searched.
#' @return loc.row returns the vector of row numbers from the \code{dfCol} which have values in to \code{vec}
#' @description loc.row takes as input a column (\code{dfCol}) and a vector (\code{vec}) of elements and returns a single vector containing the row numbers  where the values in \code{vec} are found in column \code{dfCol}. The row numbers in the output vector have one of the values present in \code{vec} in column \code{dfCol}.
#' @examples
#' loc.row(iris[,"Species"],"versicolor")
#' loc.row(iris[,"Sepal.Length"],c(5.7,4.8))
#' loc.row(warpbreaks[,"tension"],c("H"))
#' @export
loc.row<-function(dfCol,vec)
{
  locVector<-NULL
  for (i in vec)
  {
    rowIndices<-which(dfCol==i)

    if (length(rowIndices)==0)
    {
      print(paste("wrong name",i))
      next()
    }
    else
    {
      rowLocation<-rowIndices
      locVector<-c(locVector,rowLocation)
    }

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