Skip to content

Instantly share code, notes, and snippets.

@wush978
Created December 8, 2012 17:18
Show Gist options
  • Save wush978/4241083 to your computer and use it in GitHub Desktop.
Save wush978/4241083 to your computer and use it in GitHub Desktop.
Normalization of xts
library(xts)
library(inline)
library(Rcpp)
#' normalization
#'
#' This function will normalize the input \code{Rxts}.
#'
#' @param Rxts xts object which will be normalize
#' @return NULL
normalize_xts <- rcpp(sig=c(Rxts="xts"), body='
NumericMatrix xts(Rxts);
double base_value;
for(int i = 0;i < xts.nrow();i++) {
base_value = xts(i, 0);
xts.row(i) = xts.row(i) - base_value;
xts.row(i) = xts.row(i) / base_value;
}
')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment