Created
September 24, 2021 02:43
-
-
Save brymer-meneses/08f9538535fff4b5042b58896819a443 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "5052ebd4-9342-41ed-b7b3-7e954c286e30", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"4.3" | |
], | |
"text/latex": [ | |
"4.3" | |
], | |
"text/markdown": [ | |
"4.3" | |
], | |
"text/plain": [ | |
"[1] 4.3" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"### Basic Inputs\n", | |
"## Entering numbers\n", | |
"4.3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "718f0daa-f1a8-4065-84aa-62868714c1f2", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<style>\n", | |
".list-inline {list-style: none; margin:0; padding: 0}\n", | |
".list-inline>li {display: inline-block}\n", | |
".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n", | |
"</style>\n", | |
"<ol class=list-inline><li>1</li><li>0</li><li>-1</li><li>2.5</li></ol>\n" | |
], | |
"text/latex": [ | |
"\\begin{enumerate*}\n", | |
"\\item 1\n", | |
"\\item 0\n", | |
"\\item -1\n", | |
"\\item 2.5\n", | |
"\\end{enumerate*}\n" | |
], | |
"text/markdown": [ | |
"1. 1\n", | |
"2. 0\n", | |
"3. -1\n", | |
"4. 2.5\n", | |
"\n", | |
"\n" | |
], | |
"text/plain": [ | |
"[1] 1.0 0.0 -1.0 2.5" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"### Entering a collection of numbers\n", | |
"c(1, 0, -1, 2.5)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "7728b3e9-5162-49e6-aeb8-2e682985d66e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"## What happens if we did not use the c() function?\n", | |
"# 1, 0, -1, 2.5\n", | |
"\n", | |
"# >> Error: unexpected ',' in \"1\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "52f802b4-a30e-4c06-9254-b5830ed934a7", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"'i'" | |
], | |
"text/latex": [ | |
"'i'" | |
], | |
"text/markdown": [ | |
"'i'" | |
], | |
"text/plain": [ | |
"[1] \"i\"" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"## Entering Characters\n", | |
"\n", | |
"# Insert \"\" so that R will read your input as a character\n", | |
"\"i\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "0e117046-3577-46b8-bbdd-4beeae52dbe2", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"## What happens when we remove \"\"?\n", | |
"# i\n", | |
"# Error: object 'i' not found\n", | |
"\n", | |
"# NOTE: The outputs may still vary depending on the \n", | |
"# character input. This also works when we replace the \n", | |
"# letter with numbers or symbols." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "46c64c04-193b-47cd-9a5e-b1e44b14bdcb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<style>\n", | |
".list-inline {list-style: none; margin:0; padding: 0}\n", | |
".list-inline>li {display: inline-block}\n", | |
".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n", | |
"</style>\n", | |
"<ol class=list-inline><li>'a'</li><li>'3'</li><li>'?'</li></ol>\n" | |
], | |
"text/latex": [ | |
"\\begin{enumerate*}\n", | |
"\\item 'a'\n", | |
"\\item '3'\n", | |
"\\item '?'\n", | |
"\\end{enumerate*}\n" | |
], | |
"text/markdown": [ | |
"1. 'a'\n", | |
"2. '3'\n", | |
"3. '?'\n", | |
"\n", | |
"\n" | |
], | |
"text/plain": [ | |
"[1] \"a\" \"3\" \"?\"" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Entering a collection of characters\n", | |
"c(\"a\", \"3\", \"?\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "7849918d-c0dd-4f23-9992-f9fa30f0cff9", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"'Math 101'" | |
], | |
"text/latex": [ | |
"'Math 101'" | |
], | |
"text/markdown": [ | |
"'Math 101'" | |
], | |
"text/plain": [ | |
"[1] \"Math 101\"" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<style>\n", | |
".list-inline {list-style: none; margin:0; padding: 0}\n", | |
".list-inline>li {display: inline-block}\n", | |
".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n", | |
"</style>\n", | |
"<ol class=list-inline><li>'hello'</li><li>'world'</li></ol>\n" | |
], | |
"text/latex": [ | |
"\\begin{enumerate*}\n", | |
"\\item 'hello'\n", | |
"\\item 'world'\n", | |
"\\end{enumerate*}\n" | |
], | |
"text/markdown": [ | |
"1. 'hello'\n", | |
"2. 'world'\n", | |
"\n", | |
"\n" | |
], | |
"text/plain": [ | |
"[1] \"hello\" \"world\"" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Entering Strings\n", | |
"\"Math 101\"\n", | |
"\n", | |
"# Entering a collection of strings\n", | |
"c(\"hello\", \"world\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"id": "96d6f659-2fd1-468d-8258-df79f22f4156", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Naming a collection\n", | |
"c = c(1, 2, 3, 4, 5, 6, -1, -2, 0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"id": "3628c4cb-00bc-432d-838a-f93f50585345", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<style>\n", | |
".list-inline {list-style: none; margin:0; padding: 0}\n", | |
".list-inline>li {display: inline-block}\n", | |
".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n", | |
"</style>\n", | |
"<ol class=list-inline><li>3</li><li>5</li><li>7</li></ol>\n" | |
], | |
"text/latex": [ | |
"\\begin{enumerate*}\n", | |
"\\item 3\n", | |
"\\item 5\n", | |
"\\item 7\n", | |
"\\end{enumerate*}\n" | |
], | |
"text/markdown": [ | |
"1. 3\n", | |
"2. 5\n", | |
"3. 7\n", | |
"\n", | |
"\n" | |
], | |
"text/plain": [ | |
"[1] 3 5 7" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Some basic R Operations\n", | |
"## Element wise Addition/Vector Addition\n", | |
"\n", | |
"x = c(1, 2, 3)\n", | |
"y = c(2, 3, 4)\n", | |
"x + y" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"id": "1bf1cdeb-20dc-45de-8f02-ca2f86ebcc8d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<table class=\"dataframe\">\n", | |
"<caption>A matrix: 3 × 3 of type dbl</caption>\n", | |
"<thead>\n", | |
"\t<tr><th scope=col>x</th><th scope=col>y</th><th scope=col>z</th></tr>\n", | |
"</thead>\n", | |
"<tbody>\n", | |
"\t<tr><td>1</td><td>2</td><td>3</td></tr>\n", | |
"\t<tr><td>2</td><td>3</td><td>4</td></tr>\n", | |
"\t<tr><td>3</td><td>4</td><td>5</td></tr>\n", | |
"</tbody>\n", | |
"</table>\n" | |
], | |
"text/latex": [ | |
"A matrix: 3 × 3 of type dbl\n", | |
"\\begin{tabular}{lll}\n", | |
" x & y & z\\\\\n", | |
"\\hline\n", | |
"\t 1 & 2 & 3\\\\\n", | |
"\t 2 & 3 & 4\\\\\n", | |
"\t 3 & 4 & 5\\\\\n", | |
"\\end{tabular}\n" | |
], | |
"text/markdown": [ | |
"\n", | |
"A matrix: 3 × 3 of type dbl\n", | |
"\n", | |
"| x | y | z |\n", | |
"|---|---|---|\n", | |
"| 1 | 2 | 3 |\n", | |
"| 2 | 3 | 4 |\n", | |
"| 3 | 4 | 5 |\n", | |
"\n" | |
], | |
"text/plain": [ | |
" x y z\n", | |
"[1,] 1 2 3\n", | |
"[2,] 2 3 4\n", | |
"[3,] 3 4 5" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Matrices <3\n", | |
"\n", | |
"x = c(1, 2, 3)\n", | |
"y = c(2, 3, 4)\n", | |
"z = c(3, 4, 5)\n", | |
"cbind(x,y,z)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"id": "a7e0606a-7561-4800-87b1-e9d598b84af2", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<table class=\"dataframe\">\n", | |
"<caption>A matrix: 3 × 3 of type dbl</caption>\n", | |
"<tbody>\n", | |
"\t<tr><th scope=row>x</th><td>1</td><td>2</td><td>3</td></tr>\n", | |
"\t<tr><th scope=row>y</th><td>2</td><td>3</td><td>4</td></tr>\n", | |
"\t<tr><th scope=row>z</th><td>3</td><td>4</td><td>5</td></tr>\n", | |
"</tbody>\n", | |
"</table>\n" | |
], | |
"text/latex": [ | |
"A matrix: 3 × 3 of type dbl\n", | |
"\\begin{tabular}{r|lll}\n", | |
"\tx & 1 & 2 & 3\\\\\n", | |
"\ty & 2 & 3 & 4\\\\\n", | |
"\tz & 3 & 4 & 5\\\\\n", | |
"\\end{tabular}\n" | |
], | |
"text/markdown": [ | |
"\n", | |
"A matrix: 3 × 3 of type dbl\n", | |
"\n", | |
"| x | 1 | 2 | 3 |\n", | |
"| y | 2 | 3 | 4 |\n", | |
"| z | 3 | 4 | 5 |\n", | |
"\n" | |
], | |
"text/plain": [ | |
" [,1] [,2] [,3]\n", | |
"x 1 2 3 \n", | |
"y 2 3 4 \n", | |
"z 3 4 5 " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Matrices <3\n", | |
"x = c(1, 2, 3)\n", | |
"y = c(2, 3, 4)\n", | |
"z = c(3, 4, 5)\n", | |
"rbind(x,y,z)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"id": "3e44573d-5916-4eae-a46d-5ceb4ffe9616", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"1" | |
], | |
"text/latex": [ | |
"1" | |
], | |
"text/markdown": [ | |
"1" | |
], | |
"text/plain": [ | |
"[1] 1" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"rbind(x, y,z)[1][1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"id": "2d86dd3b-0a95-4fac-b1c5-3e34de276f6a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<strong>z:</strong> 5" | |
], | |
"text/latex": [ | |
"\\textbf{z:} 5" | |
], | |
"text/markdown": [ | |
"**z:** 5" | |
], | |
"text/plain": [ | |
"z \n", | |
"5 " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"x = c(1, 2, 3)\n", | |
"y = c(2, 3, 4)\n", | |
"z = c(3, 4, 5)\n", | |
"rbind(x,y,z)[3,3]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "5880cd47-0ff1-43b7-8c30-181676b2aaa4", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"iris <- read.csv(\"iris.csv\", " | |
] | |
} | |
], | |
"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": "4.1.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you