Skip to content

Instantly share code, notes, and snippets.

@tyleransom
Last active February 10, 2018 20:48
Show Gist options
  • Save tyleransom/30e8862af9c3fb96e7f92d36b681d375 to your computer and use it in GitHub Desktop.
Save tyleransom/30e8862af9c3fb96e7f92d36b681d375 to your computer and use it in GitHub Desktop.

Rosetta Stone

This consists of a "Rosetta Stone" of code syntax between R, Python, and Julia. The aim is to help those who are proficient in one language easily translate their code/understanding to another.

Basic actions (REPL, package ecosystem, etc.)

Action R code Python code Julia code
execute script from REPL source('script.R') execfile('script.py') include("script.jl")
install a package install.packages("pkg") [from OS terminal]: pip install pkg Pkg.add("pkg")
load a package library(pkg) or require(pkg) import pkg using pkg
execute shell command system('command') call(["command"]) [req. subprocess package] run(`command`)
what kind of object is x? class(x) type(x) typeof(x)

Working with arrays

Action R code Python code Julia code
array indexing x[] x[] x[]
first index 1 0 1
last element of x x[length(x)] x[-1] x[end]

Working with data frames

Action R code Python code Julia code
data frame package? native pandas DataFrames
convert array to data frame? df <- as.data.frame(array) df = DataFrame(array)
read CSV to data frame? read.csv('file.csv') readtable("file.csv")
convert JSON to data frame? library(jsonlite); df <- fromJSON('file.json')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment