R/loc.col.R

Defines functions loc.col

Documented in loc.col

#'loc.col
#' @param dfData a data.frame object in which the search should be performed. Note that this is not a character string but the data.frame object itself. The parameter passed to the function should be without quotes (" ").
#' @param colNameVec a string or a vector of class character indicating the name(s) of the column(s) to be searched.   
#' @return loc.col returns a data.frame object containing the column name and the column location for columns from \code{colNameVec} in \code{dfData}.
#' @description loc.col takes as input a data.frame object (\code{dfData}) and a character vector (\code{colNameVec}) of column names and returns a data.frame object displaying the location of the column names from \code{colNameVec} in \code{dfData}. Column names in \code{colNameVec} which cannot be found in \code{dfData} are not included in the output data.frame object.
#' @examples
#' loc.col(warpbreaks,c("tension","wool"))
#' loc.col(iris,c("Species","Sepal.Length"))
#' @export
loc.col<-function(dfData,colNameVec)
{
  locTab<-NULL
  for (i in colNameVec)
  {
    colLocation<-which(names(dfData)==i)

    if (length(colLocation)==0)
    {
      next()
    }
    else
    {
      rowLocation<-data.frame(colName=i,colLocation=colLocation)

    }

    if (length(locTab)==0)
    {
      locTab<-data.frame(colName=i,colLocation=colLocation)
    }
    else
    {
      locTab<-rbind(locTab,rowLocation)
    }

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