Skip to content

Instantly share code, notes, and snippets.

@anriseth
Created September 2, 2015 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anriseth/1dae45b7b5dac51b2485 to your computer and use it in GitHub Desktop.
Save anriseth/1dae45b7b5dac51b2485 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Use markdown with Jupyter R kernel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can add latex $\\sum_{i=1}^n f(x) = F(x)$, and links to [google](http://google.com)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can add code as markdown, eg python\n",
"```python\n",
"def f(x):\n",
" \"\"\"a docstring\"\"\"\n",
" return x**2\n",
"```\n",
"or R\n",
"```r\n",
"# Goals: A first look at R objects - vectors, lists, matrices, data frames.\n",
"\n",
"# To make vectors \"x\" \"y\" \"year\" and \"names\"\n",
"x <- c(2,3,7,9)\n",
"y <- c(9,7,3,2)\n",
"year <- 1990:1993\n",
"names <- c(\"payal\", \"shraddha\", \"kritika\", \"itida\")\n",
"# Accessing the 1st and last elements of y --\n",
"y[1]\n",
"y[length(y)]\n",
"\n",
"# To make a list \"person\" --\n",
"person <- list(name=\"payal\", x=2, y=9, year=1990)\n",
"person\n",
"# Accessing things inside a list --\n",
"person$name\n",
"person$x\n",
"\n",
"# To make a matrix, pasting together the columns \"year\" \"x\" and \"y\"\n",
"# The verb cbind() stands for \"column bind\"\n",
"cbind(year, x, y)\n",
"\n",
"# To make a \"data frame\", which is a list of vectors of the same length --\n",
"D <- data.frame(names, year, x, y)\n",
"nrow(D)\n",
"# Accessing one of these vectors\n",
"D$names\n",
"# Accessing the last element of this vector\n",
"D$names[nrow(D)]\n",
"# Or equally,\n",
"D$names[length(D$names)]\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also add the code of R, and it will show the input below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Goals: A first look at R objects - vectors, lists, matrices, data frames.\n",
"\n",
"# To make vectors \"x\" \"y\" \"year\" and \"names\"\n",
"x <- c(2,3,7,9)\n",
"y <- c(9,7,3,2)\n",
"year <- 1990:1993\n",
"names <- c(\"payal\", \"shraddha\", \"kritika\", \"itida\")\n",
"# Accessing the 1st and last elements of y --\n",
"y[1]\n",
"y[length(y)]\n",
"\n",
"# To make a list \"person\" --\n",
"person <- list(name=\"payal\", x=2, y=9, year=1990)\n",
"person\n",
"# Accessing things inside a list --\n",
"person$name\n",
"person$x\n",
"\n",
"# To make a matrix, pasting together the columns \"year\" \"x\" and \"y\"\n",
"# The verb cbind() stands for \"column bind\"\n",
"cbind(year, x, y)\n",
"\n",
"# To make a \"data frame\", which is a list of vectors of the same length --\n",
"D <- data.frame(names, year, x, y)\n",
"nrow(D)\n",
"# Accessing one of these vectors\n",
"D$names\n",
"# Accessing the last element of this vector\n",
"D$names[nrow(D)]\n",
"# Or equally,\n",
"D$names[length(D$names)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment