#' rename data
#'
#'
#' @param data A data frame
#' @param old old name, a vector
#' @param new new name, a vector
#'
#' @examples
#'
#' dat <- data.frame(a = c(1,2,3),b=c("1","a","b"),c=c(1,2,5))
#' rename_dat <- data.frame(old=c("a","b"),new=c("aa","bb"))
#' data_new <- rename(dat,old=rename_dat$old,new= rename_dat$new)
#'
#' @name rename
#' @rdname rename
#' @export
#'
rename <- function(data,
old=NULL,
new=NULL
)
{
old <- as.character(old);
new <- as.character(new);
if(length(old)!=length(new))
{
stop("Error, there must be equal numbers in old and new ")
}
for(i in 1:length(old))
{
tmpOld <- old[i];
tmpNew <- new[i];
names(data)[names(data)== tmpOld] <- tmpNew;
}
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.