Skip to content

Instantly share code, notes, and snippets.

@timcdlucas
Last active January 26, 2016 15:23
Show Gist options
  • Save timcdlucas/1c6899245bebf54b857b to your computer and use it in GitHub Desktop.
Save timcdlucas/1c6899245bebf54b857b to your computer and use it in GitHub Desktop.
R to Mathematica
# Print an R matrix in a form that can be copied straight into mathematica
MathematicaPaste.matrix <- function(m){
charmat <- apply(m, 2, as.numeric)
charmat[, -NCOL(charmat)] <- paste0(charmat[, -NCOL(charmat)], ',')
charmat <- rbind('{', t(charmat), '},')
charmat[dim(charmat)[1], dim(charmat)[2]] <- '}'
cat(paste0('{', paste(charmat, collapse = ''), '}\n'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment