#' Replace Vector Names from a Lookup Vector
#'
#' Replace vector names using a named vector that is used as a look up table.
#' @param x A frequency vector or another vector with \code{"names"} attribute set.
#' @param lookup A named character vector.
#' @return If a name in \code{"x"} matches a value in \code{"lookup"}, it is replaced from the name of the matched item in \code{"lookup"}.
#' @examples
#' punctNames <- setNames(c("\t", "\n", "\r", "\u00a0", "\u2028", "\u2029"),
#'                        c("tab", "lf", "cr", "nbsp", "line", "para"))
#' hits <- setNames(1:5, c("a", "b", "\t", "c", "\u00a0"))
#' replaceNameMatches(hits, punctNames)
#' @export
replaceNameMatches <- function(x, lookup)
{
	hits <- match(names(x), lookup, nomatch = 0)
	for (i in 1:length(x)) 
		if (hits[i] > 0) 
			names(x)[i] <- names(lookup)[hits[i]]
	return(x)
}
