A common data manipulation task is that of making 'wide' data 'long':
for example, using the reshape2
library,
library(reshape2)
wide_df <- data.frame( stringsAsFactors=FALSE,
// [[Rcpp::depends(RcppGSL)]] | |
#include <gsl/gsl_randist.h> | |
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
NumericVector gsl_dexp(NumericVector x) { | |
int n = x.size(); |
`|` <- function(x, y) { | |
if (is.data.frame(x)) { | |
return( eval(call("%.%", substitute(x), substitute(y)), envir=parent.frame()) ) | |
} else { | |
return( base::"|"(x, y) ) | |
} | |
} | |
library(dplyr) | |
mtcars | |
// run me by installing Rcpp and calling sourceCpp on this file | |
#include <Rcpp.h> | |
using namespace Rcpp; | |
// some initial stuff borrowed from R sources | |
#ifdef WORDS_BIGENDIAN | |
static const int hw = 0; | |
static const int lw = 1; |
case2 <- function(n = 10, mu = 3, sigma = sqrt(5), p = 0.025, rep = 100){ | |
xbar <- vapply(1:rep, FUN.VALUE=numeric(1), function(i) { | |
norm <- rnorm(mean = mu, sd = sigma, n = n) | |
return(mean(norm)) | |
}) | |
low <- xbar - qnorm(1-p) * (sigma / sqrt(n)) | |
up <- xbar + qnorm(1-p) * (sigma / sqrt(n)) | |
rem <- mu > low & mu < up |
git_status <- '' | |
class(git_status) <- "__git_status__" | |
print.__git_status__ <- function(x, ...) system("git status") | |
git_status ## prints 'git status' for the current dir |
// This code copied and modified from the R sources (src/main/apply.c) for do_lapply. | |
// Essentially, we remove some of the op / arity checking, and then | |
// construct a call to FUN that also passes the index. | |
#define USE_RINTERNALS | |
#include <R.h> | |
#include <Rinternals.h> | |
// [[export]] |
#include <Rcpp.h> | |
using namespace Rcpp; | |
union DoublePunner { | |
double d; | |
uint64_t p; | |
}; | |
static DoublePunner NA_PUNNED = { NA_REAL }; |
#define debug | |
#ifdef DEBUG | |
#define debug(x) Rprintf(x) | |
#define debug2(x, y) Rprintf(x, y) | |
#define debug3(x, y, z) Rprintf(x, y, z) | |
#else | |
#define debug(x) | |
#define debug2(x, y) | |
#define debug3(x, y, z) |
library(shiny) | |
shinyServer( function(input, output, session) { | |
}) |