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,| <!doctype HTML> | |
| <meta charset = 'utf-8'> | |
| <html> | |
| <head> | |
| <script src='http://polychart.com/s/third_party/polychart2.standalone.js' type='text/javascript'></script> | |
| <style> | |
| .rChart { | |
| display: block; |
| // [[Rcpp::depends(RcppArmadillo)]] | |
| #include <RcppArmadillo.h> | |
| // [[Rcpp::export]] | |
| arma::imat shuffle(arma::imat A) { | |
| for (int i=0; i < A.n_rows; ++i) { | |
| A.row(i) = shuffle( A.row(i), 1 ); | |
| } | |
| return A; |
| .Rproj.user | |
| .Rhistory | |
| .RData | |
| *.Rproj | |
| *.html |
| library(shiny) | |
| shinyServer( function(input, output, session) { | |
| }) |
| #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) |
| #include <Rcpp.h> | |
| using namespace Rcpp; | |
| union DoublePunner { | |
| double d; | |
| uint64_t p; | |
| }; | |
| static DoublePunner NA_PUNNED = { NA_REAL }; |
| // 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]] |
| git_status <- '' | |
| class(git_status) <- "__git_status__" | |
| print.__git_status__ <- function(x, ...) system("git status") | |
| git_status ## prints 'git status' for the current dir |
| 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 |