2044 lines
185 KiB
Plaintext
2044 lines
185 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "7f05d56c-1de6-459d-a3b0-2e02d90cff5d",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Bardzo krótkie wprowadzenie do programu R\n",
|
|||
|
"\n",
|
|||
|
"## Podstawowe informacje\n",
|
|||
|
"\n",
|
|||
|
"* R - język programowania / pakiet statystyczny.\n",
|
|||
|
"* Jest to język darmowy, rozpowszechniany na licencji GNU General Public License (GPL).\n",
|
|||
|
"* Jest przydatny szczególnie dla osób zainteresowanych statystyką/analizą danych.\n",
|
|||
|
"* R zawiera ponad 10000 pakietów do różnych zastosowań.\n",
|
|||
|
"* Program R można pobrać z następującej [strony](https://cran.r-project.org/).\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "08e52962-d702-40bb-8b4e-d5e91f96fd3f",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## RStudio\n",
|
|||
|
"\n",
|
|||
|
"* R studio - edytor do programu R, ułatwiający pracę z tym programem.\n",
|
|||
|
"* dystrybuowany na licencji AGPL v3.\n",
|
|||
|
"* w RStudio można też wykonywać kody napisane w Pythonie.\n",
|
|||
|
"* RStudio można pobrać z następującej [strony](https://posit.co/products/open-source/rstudio/).\n",
|
|||
|
"* Przykładowy wygląd paneli Rstudio zaprezentowany jest poniżej.\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"![RStudio](rstudio.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "eda2cba4-2402-4c02-a6c2-b1d78cd61837",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Pakiety\n",
|
|||
|
"\n",
|
|||
|
"Aby w pełni korzystać z możliwości R, będziemy wykorzystywać różne gotowe pakiety.\n",
|
|||
|
"* Do instalacji pakietu używamy polecenia `install.packages()`.\n",
|
|||
|
"* Do załadowania pakietu używamy polecenia `library()`.\n",
|
|||
|
"* Jeśli używamy RStudio możemy wyświetlić listę zainstalowanych i załadowanych pakietów (na wcześniej zaprezentowanym rysunku znajduje się ona w prawym dolnym rogu - załadowane pakiety oznaczone są haczykiem). Ponadto, możemy też ładować pakiety klikając na kwadraciki znajdujące się na tej liście przy nazwie odpowiedniego pakietu.\n",
|
|||
|
"\n",
|
|||
|
"**Uwaga:** Nie wszystkie pakiety są dostępne w wersji online Jupytera. W związku z tym poniższy i kolejne przykłady mogą wymagać przekopiowania instrukcji do RStudio."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 42,
|
|||
|
"id": "8995ee46-f951-4196-9fa1-703ee4710e4d",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Installing package into ‘/usr/local/lib/R/site-library’\n",
|
|||
|
"(as ‘lib’ is unspecified)\n",
|
|||
|
"\n",
|
|||
|
"Warning message in install.packages(\"gtools\"):\n",
|
|||
|
"“'lib = \"/usr/local/lib/R/site-library\"' is not writable”\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"ename": "ERROR",
|
|||
|
"evalue": "Error in install.packages(\"gtools\"): unable to install packages\n",
|
|||
|
"output_type": "error",
|
|||
|
"traceback": [
|
|||
|
"Error in install.packages(\"gtools\"): unable to install packages\nTraceback:\n",
|
|||
|
"1. install.packages(\"gtools\")",
|
|||
|
"2. stop(\"unable to install packages\")"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"install.packages(\"gtools\")\n",
|
|||
|
"library(\"gtools\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "987aaa93-8f98-4715-a052-f6d247bf89ef",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Wektory i macierze\n",
|
|||
|
"\n",
|
|||
|
"Jednym z podstawowych obiektów, które będą nas interesowały w kontekście naszych zajęć są wektory i macierze.\n",
|
|||
|
"\n",
|
|||
|
"### Definiowanie wektorów\n",
|
|||
|
"\n",
|
|||
|
"Poniżej przedstawimy kilka podstawowych sposobów definiowania wektorów wraz z przykładami.\n",
|
|||
|
"\n",
|
|||
|
"* Wektory możemy przypisać do zmiennej używając jednego z operatorów: `=`, `<-`, `->`.\n",
|
|||
|
"* Podstawową funkcją służącą do definiowania wektorów jest `c()`, gdzie w nawiasach wpisujemy kolejne elementy wektora. "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 1,
|
|||
|
"id": "e4462a8a-bf7f-4abe-b91d-12596c0fe57d",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"a = c(1, 2, -4)\n",
|
|||
|
"b = c('as', 'krol', 'dama')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 2,
|
|||
|
"id": "d1989341-594b-4b3e-bc64-77f235976565",
|
|||
|
"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>2</li><li>-4</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 1\n",
|
|||
|
"\\item 2\n",
|
|||
|
"\\item -4\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 1\n",
|
|||
|
"2. 2\n",
|
|||
|
"3. -4\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 1 2 -4"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"a"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 45,
|
|||
|
"id": "8fa93538-c379-4907-b109-6f7a5fef4421",
|
|||
|
"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>'as'</li><li>'krol'</li><li>'dama'</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 'as'\n",
|
|||
|
"\\item 'krol'\n",
|
|||
|
"\\item 'dama'\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 'as'\n",
|
|||
|
"2. 'krol'\n",
|
|||
|
"3. 'dama'\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] \"as\" \"krol\" \"dama\""
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"b"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "463223a4-571c-448b-98e4-b3b56e7adbaa",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"* Polecenie `i:j`, gdzie $i,j$ to liczby całkowite, tworzy ciąg arytmetyczny o pierwszym elemencie równym $i$ oraz różnicy równej $1$ (jeśli $j>i$) lub $-1$ (jeśli $j<i$), którego ostatni wyraz nie przekracza $j$.\n",
|
|||
|
"* Polecenie `seq(from=i,to=j,by=r)`, gdzie $i,j,r$ to liczby całkowite, tworzy ciąg arytmetyczny o pierwszym elemencie równym $i$ oraz różnicy równej $r$, którego ostatni wyraz nie przekracza $j$."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 3,
|
|||
|
"id": "3def41c0-675f-4425-9a91-7968f3eca724",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"c = 2:9\n",
|
|||
|
"d = 9:2\n",
|
|||
|
"e = seq(2, 9, 3)\n",
|
|||
|
"f = seq(10, 1, -1.5)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 47,
|
|||
|
"id": "c026f39b-bb98-4deb-8bb8-3778a9e2f188",
|
|||
|
"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>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 2\n",
|
|||
|
"\\item 3\n",
|
|||
|
"\\item 4\n",
|
|||
|
"\\item 5\n",
|
|||
|
"\\item 6\n",
|
|||
|
"\\item 7\n",
|
|||
|
"\\item 8\n",
|
|||
|
"\\item 9\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 2\n",
|
|||
|
"2. 3\n",
|
|||
|
"3. 4\n",
|
|||
|
"4. 5\n",
|
|||
|
"5. 6\n",
|
|||
|
"6. 7\n",
|
|||
|
"7. 8\n",
|
|||
|
"8. 9\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 2 3 4 5 6 7 8 9"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"c"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 48,
|
|||
|
"id": "c71d4831-8d80-49e0-9a4b-085911c70070",
|
|||
|
"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>9</li><li>8</li><li>7</li><li>6</li><li>5</li><li>4</li><li>3</li><li>2</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 9\n",
|
|||
|
"\\item 8\n",
|
|||
|
"\\item 7\n",
|
|||
|
"\\item 6\n",
|
|||
|
"\\item 5\n",
|
|||
|
"\\item 4\n",
|
|||
|
"\\item 3\n",
|
|||
|
"\\item 2\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 9\n",
|
|||
|
"2. 8\n",
|
|||
|
"3. 7\n",
|
|||
|
"4. 6\n",
|
|||
|
"5. 5\n",
|
|||
|
"6. 4\n",
|
|||
|
"7. 3\n",
|
|||
|
"8. 2\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 9 8 7 6 5 4 3 2"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"d"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 49,
|
|||
|
"id": "e15280e7-d101-41dc-bd8e-afc5f9af2142",
|
|||
|
"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>2</li><li>5</li><li>8</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 2\n",
|
|||
|
"\\item 5\n",
|
|||
|
"\\item 8\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 2\n",
|
|||
|
"2. 5\n",
|
|||
|
"3. 8\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 2 5 8"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"e"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 50,
|
|||
|
"id": "33d159fc-867b-4752-a52f-3fe36ef5af62",
|
|||
|
"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>10</li><li>8.5</li><li>7</li><li>5.5</li><li>4</li><li>2.5</li><li>1</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 10\n",
|
|||
|
"\\item 8.5\n",
|
|||
|
"\\item 7\n",
|
|||
|
"\\item 5.5\n",
|
|||
|
"\\item 4\n",
|
|||
|
"\\item 2.5\n",
|
|||
|
"\\item 1\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 10\n",
|
|||
|
"2. 8.5\n",
|
|||
|
"3. 7\n",
|
|||
|
"4. 5.5\n",
|
|||
|
"5. 4\n",
|
|||
|
"6. 2.5\n",
|
|||
|
"7. 1\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 10.0 8.5 7.0 5.5 4.0 2.5 1.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"f"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "ad18788d-ade0-469a-960d-c2b776509b51",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"* Polecenie `rep(x,...)` pozwala tworzyć wektory, w których elementy się powtarzają. W tym wypadku `x` jest wektorem elementów, które mają się powtórzyć, a w miejsce kropek wpisujemy informację o tym, ile razy mają się powtórzyć elementy (jeśli wpiszemy tu liczbę $n$, to cały wektor zostanie powtórzony $n$ razy, a jeśli podamy wektor liczb `v` o tej samej długości, co `x`, to każdy element wektora `x` zostanie powtórzony tyle razy, ile wskazuje na to odpowiednia współrzędna wektora `v`)."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 4,
|
|||
|
"id": "7919afd8-5745-4cce-a159-f347c9987df7",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"g = rep(c('as', 'krol'), 2)\n",
|
|||
|
"h = rep(c('as', 'krol'), c(2, 3))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 52,
|
|||
|
"id": "28e083ab-fb20-4011-a426-319a32460cfa",
|
|||
|
"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>'as'</li><li>'krol'</li><li>'as'</li><li>'krol'</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 'as'\n",
|
|||
|
"\\item 'krol'\n",
|
|||
|
"\\item 'as'\n",
|
|||
|
"\\item 'krol'\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 'as'\n",
|
|||
|
"2. 'krol'\n",
|
|||
|
"3. 'as'\n",
|
|||
|
"4. 'krol'\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] \"as\" \"krol\" \"as\" \"krol\""
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"g"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 53,
|
|||
|
"id": "af092b89-e49c-4d55-815f-b0b7bacee3f3",
|
|||
|
"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>'as'</li><li>'as'</li><li>'krol'</li><li>'krol'</li><li>'krol'</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 'as'\n",
|
|||
|
"\\item 'as'\n",
|
|||
|
"\\item 'krol'\n",
|
|||
|
"\\item 'krol'\n",
|
|||
|
"\\item 'krol'\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 'as'\n",
|
|||
|
"2. 'as'\n",
|
|||
|
"3. 'krol'\n",
|
|||
|
"4. 'krol'\n",
|
|||
|
"5. 'krol'\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] \"as\" \"as\" \"krol\" \"krol\" \"krol\""
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"h"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "07b9abb0-6076-4a04-8a42-029f13242945",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"* Istnieje kilka wbudowanych, przydatnych wektorów, np.:\n",
|
|||
|
" * `letters`: wektor zawierajacy $26$-literowy alfabet (małe litery);\n",
|
|||
|
"\t* `LETTERS`: wektor zawierajacy $26$-literowy alfabet (duże litery);\n",
|
|||
|
"\t* `month.name`: wektor zawierający nazwy miesięcy (po angielsku)."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 54,
|
|||
|
"id": "cfae82f1-8c0d-4e46-b711-19be8ada0360",
|
|||
|
"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>'b'</li><li>'c'</li><li>'d'</li><li>'e'</li><li>'f'</li><li>'g'</li><li>'h'</li><li>'i'</li><li>'j'</li><li>'k'</li><li>'l'</li><li>'m'</li><li>'n'</li><li>'o'</li><li>'p'</li><li>'q'</li><li>'r'</li><li>'s'</li><li>'t'</li><li>'u'</li><li>'v'</li><li>'w'</li><li>'x'</li><li>'y'</li><li>'z'</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 'a'\n",
|
|||
|
"\\item 'b'\n",
|
|||
|
"\\item 'c'\n",
|
|||
|
"\\item 'd'\n",
|
|||
|
"\\item 'e'\n",
|
|||
|
"\\item 'f'\n",
|
|||
|
"\\item 'g'\n",
|
|||
|
"\\item 'h'\n",
|
|||
|
"\\item 'i'\n",
|
|||
|
"\\item 'j'\n",
|
|||
|
"\\item 'k'\n",
|
|||
|
"\\item 'l'\n",
|
|||
|
"\\item 'm'\n",
|
|||
|
"\\item 'n'\n",
|
|||
|
"\\item 'o'\n",
|
|||
|
"\\item 'p'\n",
|
|||
|
"\\item 'q'\n",
|
|||
|
"\\item 'r'\n",
|
|||
|
"\\item 's'\n",
|
|||
|
"\\item 't'\n",
|
|||
|
"\\item 'u'\n",
|
|||
|
"\\item 'v'\n",
|
|||
|
"\\item 'w'\n",
|
|||
|
"\\item 'x'\n",
|
|||
|
"\\item 'y'\n",
|
|||
|
"\\item 'z'\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 'a'\n",
|
|||
|
"2. 'b'\n",
|
|||
|
"3. 'c'\n",
|
|||
|
"4. 'd'\n",
|
|||
|
"5. 'e'\n",
|
|||
|
"6. 'f'\n",
|
|||
|
"7. 'g'\n",
|
|||
|
"8. 'h'\n",
|
|||
|
"9. 'i'\n",
|
|||
|
"10. 'j'\n",
|
|||
|
"11. 'k'\n",
|
|||
|
"12. 'l'\n",
|
|||
|
"13. 'm'\n",
|
|||
|
"14. 'n'\n",
|
|||
|
"15. 'o'\n",
|
|||
|
"16. 'p'\n",
|
|||
|
"17. 'q'\n",
|
|||
|
"18. 'r'\n",
|
|||
|
"19. 's'\n",
|
|||
|
"20. 't'\n",
|
|||
|
"21. 'u'\n",
|
|||
|
"22. 'v'\n",
|
|||
|
"23. 'w'\n",
|
|||
|
"24. 'x'\n",
|
|||
|
"25. 'y'\n",
|
|||
|
"26. 'z'\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\" \"g\" \"h\" \"i\" \"j\" \"k\" \"l\" \"m\" \"n\" \"o\" \"p\" \"q\" \"r\" \"s\"\n",
|
|||
|
"[20] \"t\" \"u\" \"v\" \"w\" \"x\" \"y\" \"z\""
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"letters"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 55,
|
|||
|
"id": "ffb30915-c2d3-48a9-a813-ba64907c9730",
|
|||
|
"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>'B'</li><li>'C'</li><li>'D'</li><li>'E'</li><li>'F'</li><li>'G'</li><li>'H'</li><li>'I'</li><li>'J'</li><li>'K'</li><li>'L'</li><li>'M'</li><li>'N'</li><li>'O'</li><li>'P'</li><li>'Q'</li><li>'R'</li><li>'S'</li><li>'T'</li><li>'U'</li><li>'V'</li><li>'W'</li><li>'X'</li><li>'Y'</li><li>'Z'</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 'A'\n",
|
|||
|
"\\item 'B'\n",
|
|||
|
"\\item 'C'\n",
|
|||
|
"\\item 'D'\n",
|
|||
|
"\\item 'E'\n",
|
|||
|
"\\item 'F'\n",
|
|||
|
"\\item 'G'\n",
|
|||
|
"\\item 'H'\n",
|
|||
|
"\\item 'I'\n",
|
|||
|
"\\item 'J'\n",
|
|||
|
"\\item 'K'\n",
|
|||
|
"\\item 'L'\n",
|
|||
|
"\\item 'M'\n",
|
|||
|
"\\item 'N'\n",
|
|||
|
"\\item 'O'\n",
|
|||
|
"\\item 'P'\n",
|
|||
|
"\\item 'Q'\n",
|
|||
|
"\\item 'R'\n",
|
|||
|
"\\item 'S'\n",
|
|||
|
"\\item 'T'\n",
|
|||
|
"\\item 'U'\n",
|
|||
|
"\\item 'V'\n",
|
|||
|
"\\item 'W'\n",
|
|||
|
"\\item 'X'\n",
|
|||
|
"\\item 'Y'\n",
|
|||
|
"\\item 'Z'\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 'A'\n",
|
|||
|
"2. 'B'\n",
|
|||
|
"3. 'C'\n",
|
|||
|
"4. 'D'\n",
|
|||
|
"5. 'E'\n",
|
|||
|
"6. 'F'\n",
|
|||
|
"7. 'G'\n",
|
|||
|
"8. 'H'\n",
|
|||
|
"9. 'I'\n",
|
|||
|
"10. 'J'\n",
|
|||
|
"11. 'K'\n",
|
|||
|
"12. 'L'\n",
|
|||
|
"13. 'M'\n",
|
|||
|
"14. 'N'\n",
|
|||
|
"15. 'O'\n",
|
|||
|
"16. 'P'\n",
|
|||
|
"17. 'Q'\n",
|
|||
|
"18. 'R'\n",
|
|||
|
"19. 'S'\n",
|
|||
|
"20. 'T'\n",
|
|||
|
"21. 'U'\n",
|
|||
|
"22. 'V'\n",
|
|||
|
"23. 'W'\n",
|
|||
|
"24. 'X'\n",
|
|||
|
"25. 'Y'\n",
|
|||
|
"26. 'Z'\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [1] \"A\" \"B\" \"C\" \"D\" \"E\" \"F\" \"G\" \"H\" \"I\" \"J\" \"K\" \"L\" \"M\" \"N\" \"O\" \"P\" \"Q\" \"R\" \"S\"\n",
|
|||
|
"[20] \"T\" \"U\" \"V\" \"W\" \"X\" \"Y\" \"Z\""
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"LETTERS"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 56,
|
|||
|
"id": "db9ffde1-3453-4e97-8f30-c1d95f1f716e",
|
|||
|
"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>'January'</li><li>'February'</li><li>'March'</li><li>'April'</li><li>'May'</li><li>'June'</li><li>'July'</li><li>'August'</li><li>'September'</li><li>'October'</li><li>'November'</li><li>'December'</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 'January'\n",
|
|||
|
"\\item 'February'\n",
|
|||
|
"\\item 'March'\n",
|
|||
|
"\\item 'April'\n",
|
|||
|
"\\item 'May'\n",
|
|||
|
"\\item 'June'\n",
|
|||
|
"\\item 'July'\n",
|
|||
|
"\\item 'August'\n",
|
|||
|
"\\item 'September'\n",
|
|||
|
"\\item 'October'\n",
|
|||
|
"\\item 'November'\n",
|
|||
|
"\\item 'December'\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 'January'\n",
|
|||
|
"2. 'February'\n",
|
|||
|
"3. 'March'\n",
|
|||
|
"4. 'April'\n",
|
|||
|
"5. 'May'\n",
|
|||
|
"6. 'June'\n",
|
|||
|
"7. 'July'\n",
|
|||
|
"8. 'August'\n",
|
|||
|
"9. 'September'\n",
|
|||
|
"10. 'October'\n",
|
|||
|
"11. 'November'\n",
|
|||
|
"12. 'December'\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [1] \"January\" \"February\" \"March\" \"April\" \"May\" \"June\" \n",
|
|||
|
" [7] \"July\" \"August\" \"September\" \"October\" \"November\" \"December\" "
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"month.name"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "10deab8f-4fb1-4091-ad6c-e5c3acf0a930",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Definiowanie macierzy\n",
|
|||
|
"\n",
|
|||
|
"Pokażemy teraz, jak możemy definiować macierze.\n",
|
|||
|
"\n",
|
|||
|
"* Podstawowym poleceniem do generowania macierzy jest `matrix(v, nrow=n, ncol=m, byrow=FALSE)`, gdzie `v` jest wektorem danych do wpisania do macierzy, `nrow` i `ncol` oznaczają odpowiednio liczbę wierszy i kolumn w macierzy, a `byrow` zawiera informację o tym, w jaki sposób elementy wektora `v` mają być wpisywane do macierzy. Jeśli `byrow` ma wartość `TRUE`, to kolejne elementy będą wpisywane w kolejne wiersze macierzy, w przeciwnym przypadku będą wpisywane w kolejnych kolumnach. Nie jest konieczne podawanie zarówno liczby wierszy, jak i kolumn - jeśli podamy tylko jeden wymiar, drugi zostanie wybrany automatycznie tak, aby do macierzy można było wpisać wszystkie elementy wektora `v`. Jeśli iloczyn liczb $n$ i $m$ jest większy niż długość wektora `v`, to w brakujące miejsca są ponownie wstawiane elementy początkowe wektora `v`. Jeśli natomiast ten iloczyn będzie mniejszy od długości wektora `v`, to do macierzy zostaną wpisane tylko początkowe elementy wektora, a pozostałe zostaną zignorowane. W obu przypadkach zostanie wyświetlone ostrzeżenie o braku kompatybilności wymiarów."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 57,
|
|||
|
"id": "0dfa778b-9078-4905-b7ff-be0167b8af63",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Warning message in matrix(m, nrow = 5):\n",
|
|||
|
"“data length [12] is not a sub-multiple or multiple of the number of rows [5]”\n",
|
|||
|
"Warning message in matrix(m, nrow = 2, ncol = 3):\n",
|
|||
|
"“data length differs from size of matrix: [12 != 2 x 3]”\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Definiujemy macierze, których elementami są nazwy miesięcy\n",
|
|||
|
"m = month.name\n",
|
|||
|
"\n",
|
|||
|
"# Zwróćmy uwagę, że w macierzy M1 nazwy miesięcy wpisywane są kolejno wierszami\n",
|
|||
|
"M1 = matrix(m, nrow=3, ncol=4, byrow=TRUE)\n",
|
|||
|
"# Natomiast w macierzy M2 nazwy wpisywane są kolejno kolumnami\n",
|
|||
|
"M2 = matrix(m, nrow=3, ncol=4, byrow=FALSE)\n",
|
|||
|
"\n",
|
|||
|
"# W macierzy M3 liczba wierszy nie jest dzielnikiem długości wektora m, więc niektóre elementy tego wektora zostaną wykorzystane wielokrotnie\n",
|
|||
|
"M3 = matrix(m, nrow=5)\n",
|
|||
|
"# Liczba elementów macierzy M4 jest mniejsza od długości wektora m, więc jego końcowe elementy nie zostaną wykorzystane\n",
|
|||
|
"M4 = matrix(m, nrow=2, ncol=3)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 58,
|
|||
|
"id": "b41572e7-855c-4cee-97aa-68a4861a4046",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 3 × 4 of type chr</caption>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><td>January </td><td>February</td><td>March </td><td>April </td></tr>\n",
|
|||
|
"\t<tr><td>May </td><td>June </td><td>July </td><td>August </td></tr>\n",
|
|||
|
"\t<tr><td>September</td><td>October </td><td>November</td><td>December</td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 3 × 4 of type chr\n",
|
|||
|
"\\begin{tabular}{llll}\n",
|
|||
|
"\t January & February & March & April \\\\\n",
|
|||
|
"\t May & June & July & August \\\\\n",
|
|||
|
"\t September & October & November & December\\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 3 × 4 of type chr\n",
|
|||
|
"\n",
|
|||
|
"| January | February | March | April |\n",
|
|||
|
"| May | June | July | August |\n",
|
|||
|
"| September | October | November | December |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [,1] [,2] [,3] [,4] \n",
|
|||
|
"[1,] January February March April \n",
|
|||
|
"[2,] May June July August \n",
|
|||
|
"[3,] September October November December"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"M1"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 59,
|
|||
|
"id": "e8d16065-e3c8-4485-91ec-cfde30aaaa3e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 3 × 4 of type chr</caption>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><td>January </td><td>April</td><td>July </td><td>October </td></tr>\n",
|
|||
|
"\t<tr><td>February</td><td>May </td><td>August </td><td>November</td></tr>\n",
|
|||
|
"\t<tr><td>March </td><td>June </td><td>September</td><td>December</td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 3 × 4 of type chr\n",
|
|||
|
"\\begin{tabular}{llll}\n",
|
|||
|
"\t January & April & July & October \\\\\n",
|
|||
|
"\t February & May & August & November\\\\\n",
|
|||
|
"\t March & June & September & December\\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 3 × 4 of type chr\n",
|
|||
|
"\n",
|
|||
|
"| January | April | July | October |\n",
|
|||
|
"| February | May | August | November |\n",
|
|||
|
"| March | June | September | December |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [,1] [,2] [,3] [,4] \n",
|
|||
|
"[1,] January April July October \n",
|
|||
|
"[2,] February May August November\n",
|
|||
|
"[3,] March June September December"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"M2"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 60,
|
|||
|
"id": "f7af34fa-585d-4fc2-bd2d-db9b8c02df94",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 5 × 3 of type chr</caption>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><td>January </td><td>June </td><td>November</td></tr>\n",
|
|||
|
"\t<tr><td>February</td><td>July </td><td>December</td></tr>\n",
|
|||
|
"\t<tr><td>March </td><td>August </td><td>January </td></tr>\n",
|
|||
|
"\t<tr><td>April </td><td>September</td><td>February</td></tr>\n",
|
|||
|
"\t<tr><td>May </td><td>October </td><td>March </td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 5 × 3 of type chr\n",
|
|||
|
"\\begin{tabular}{lll}\n",
|
|||
|
"\t January & June & November\\\\\n",
|
|||
|
"\t February & July & December\\\\\n",
|
|||
|
"\t March & August & January \\\\\n",
|
|||
|
"\t April & September & February\\\\\n",
|
|||
|
"\t May & October & March \\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 5 × 3 of type chr\n",
|
|||
|
"\n",
|
|||
|
"| January | June | November |\n",
|
|||
|
"| February | July | December |\n",
|
|||
|
"| March | August | January |\n",
|
|||
|
"| April | September | February |\n",
|
|||
|
"| May | October | March |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [,1] [,2] [,3] \n",
|
|||
|
"[1,] January June November\n",
|
|||
|
"[2,] February July December\n",
|
|||
|
"[3,] March August January \n",
|
|||
|
"[4,] April September February\n",
|
|||
|
"[5,] May October March "
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"M3"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 61,
|
|||
|
"id": "34b7a896-840c-4527-93c0-6d331799ece6",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 2 × 3 of type chr</caption>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><td>January </td><td>March</td><td>May </td></tr>\n",
|
|||
|
"\t<tr><td>February</td><td>April</td><td>June</td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 2 × 3 of type chr\n",
|
|||
|
"\\begin{tabular}{lll}\n",
|
|||
|
"\t January & March & May \\\\\n",
|
|||
|
"\t February & April & June\\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 2 × 3 of type chr\n",
|
|||
|
"\n",
|
|||
|
"| January | March | May |\n",
|
|||
|
"| February | April | June |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [,1] [,2] [,3]\n",
|
|||
|
"[1,] January March May \n",
|
|||
|
"[2,] February April June"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"M4"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "44e0a572-3f98-4db1-a74b-492f73d8f6f7",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"* Jeśli mamy dany wektor `v` o długości $k$, to możemy zamienić go na macierz dwuwymiarową o wymiarach $n\\times m$ (gdzie $k=n\\cdot m$), używając polecenia `dim(v)=c(n,m)`. Wówczas elementy wektora `v` zostaną wpisane kolejno kolumnami do macierzy. \n",
|
|||
|
"* Jeśli mamy dany ciąg wektorów/macierzy, to możemy je połączyć w większy obiekt używając poleceń `rbind` (obiekty będą łaczone wierszowo, tzn. kolejne wektory/macierze będą wpisywane w kolejne wiersze tworzonej tabeli) lub `cbind` (obiekty będą łączone kolumnowo, tzn. kolejne wektory/macierze będą wpisywane w kolejne kolumny tworzonej tabeli)."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 6,
|
|||
|
"id": "10e6b05f-e9c6-4e93-aa59-f103b5281b13",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 4 × 2 of type int</caption>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><td>2</td><td>6</td></tr>\n",
|
|||
|
"\t<tr><td>3</td><td>7</td></tr>\n",
|
|||
|
"\t<tr><td>4</td><td>8</td></tr>\n",
|
|||
|
"\t<tr><td>5</td><td>9</td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 4 × 2 of type int\n",
|
|||
|
"\\begin{tabular}{ll}\n",
|
|||
|
"\t 2 & 6\\\\\n",
|
|||
|
"\t 3 & 7\\\\\n",
|
|||
|
"\t 4 & 8\\\\\n",
|
|||
|
"\t 5 & 9\\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 4 × 2 of type int\n",
|
|||
|
"\n",
|
|||
|
"| 2 | 6 |\n",
|
|||
|
"| 3 | 7 |\n",
|
|||
|
"| 4 | 8 |\n",
|
|||
|
"| 5 | 9 |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [,1] [,2]\n",
|
|||
|
"[1,] 2 6 \n",
|
|||
|
"[2,] 3 7 \n",
|
|||
|
"[3,] 4 8 \n",
|
|||
|
"[4,] 5 9 "
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"dim(c) = c(4,2)\n",
|
|||
|
"c"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 7,
|
|||
|
"id": "0f4d44ac-cc7d-488e-97dd-f8aa18cd7da6",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 2 × 3 of type dbl</caption>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><th scope=row>a</th><td>1</td><td>2</td><td>-4</td></tr>\n",
|
|||
|
"\t<tr><th scope=row>e</th><td>2</td><td>5</td><td> 8</td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 2 × 3 of type dbl\n",
|
|||
|
"\\begin{tabular}{r|lll}\n",
|
|||
|
"\ta & 1 & 2 & -4\\\\\n",
|
|||
|
"\te & 2 & 5 & 8\\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 2 × 3 of type dbl\n",
|
|||
|
"\n",
|
|||
|
"| a | 1 | 2 | -4 |\n",
|
|||
|
"| e | 2 | 5 | 8 |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [,1] [,2] [,3]\n",
|
|||
|
"a 1 2 -4 \n",
|
|||
|
"e 2 5 8 "
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"A = rbind(a, e)\n",
|
|||
|
"A"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 8,
|
|||
|
"id": "c01f0693-4ccb-4db5-95ec-de65a2c99395",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 3 × 2 of type dbl</caption>\n",
|
|||
|
"<thead>\n",
|
|||
|
"\t<tr><th scope=col>a</th><th scope=col>e</th></tr>\n",
|
|||
|
"</thead>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><td> 1</td><td>2</td></tr>\n",
|
|||
|
"\t<tr><td> 2</td><td>5</td></tr>\n",
|
|||
|
"\t<tr><td>-4</td><td>8</td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 3 × 2 of type dbl\n",
|
|||
|
"\\begin{tabular}{ll}\n",
|
|||
|
" a & e\\\\\n",
|
|||
|
"\\hline\n",
|
|||
|
"\t 1 & 2\\\\\n",
|
|||
|
"\t 2 & 5\\\\\n",
|
|||
|
"\t -4 & 8\\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 3 × 2 of type dbl\n",
|
|||
|
"\n",
|
|||
|
"| a | e |\n",
|
|||
|
"|---|---|\n",
|
|||
|
"| 1 | 2 |\n",
|
|||
|
"| 2 | 5 |\n",
|
|||
|
"| -4 | 8 |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" a e\n",
|
|||
|
"[1,] 1 2\n",
|
|||
|
"[2,] 2 5\n",
|
|||
|
"[3,] -4 8"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"B = cbind(a, e)\n",
|
|||
|
"B"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "233dc3e1-11a2-4856-88ff-ee433b1e6958",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Odwoływanie się do elementów wektora / macierzy\n",
|
|||
|
"\n",
|
|||
|
"Pokażemy teraz, w jaki sposób możemy odwoływać się do elementów danego wektora `v`\n",
|
|||
|
"\n",
|
|||
|
"* `v[i]` - $i$-ty element wektora `v` (wektory indeksowane są od $1$);\n",
|
|||
|
"* `v[x]`, gdzie `x` jest wektorem indeksów zwraca elementy wektora `v` o indeksach podanych w wektorze `x`;\n",
|
|||
|
"* `v[-i]` - wszystkie elementy wektora `v` poza $i$-tym;\n",
|
|||
|
"* `v[-x]`, gdzie `x` jest wektorem indeksów - wszystkie elementy wektora `v` poza tymi, których indeksy są podane w wektorze `x`;\n",
|
|||
|
"* do wskazywania podciągu elementów wektora `v` można też używać warunków logicznych."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 65,
|
|||
|
"id": "a7b3fcf7-6bce-45cc-8337-c481b7a39554",
|
|||
|
"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>10</li><li>8.5</li><li>7</li><li>5.5</li><li>4</li><li>2.5</li><li>1</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 10\n",
|
|||
|
"\\item 8.5\n",
|
|||
|
"\\item 7\n",
|
|||
|
"\\item 5.5\n",
|
|||
|
"\\item 4\n",
|
|||
|
"\\item 2.5\n",
|
|||
|
"\\item 1\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 10\n",
|
|||
|
"2. 8.5\n",
|
|||
|
"3. 7\n",
|
|||
|
"4. 5.5\n",
|
|||
|
"5. 4\n",
|
|||
|
"6. 2.5\n",
|
|||
|
"7. 1\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 10.0 8.5 7.0 5.5 4.0 2.5 1.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"f"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 66,
|
|||
|
"id": "5f5afe35-59c2-48a7-b0bb-9751bf9e0888",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"7"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"7"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"7"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 7"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"f[3]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 67,
|
|||
|
"id": "2e9931da-d2d3-4840-a08a-b1b68f953a7f",
|
|||
|
"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>7</li><li>10</li><li>5.5</li><li>7</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 7\n",
|
|||
|
"\\item 10\n",
|
|||
|
"\\item 5.5\n",
|
|||
|
"\\item 7\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 7\n",
|
|||
|
"2. 10\n",
|
|||
|
"3. 5.5\n",
|
|||
|
"4. 7\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 7.0 10.0 5.5 7.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"f[c(3,1,4,3)]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 68,
|
|||
|
"id": "7c56154d-7b5c-4267-b640-fa220af94480",
|
|||
|
"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>10</li><li>8.5</li><li>7</li><li>5.5</li><li>2.5</li><li>1</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 10\n",
|
|||
|
"\\item 8.5\n",
|
|||
|
"\\item 7\n",
|
|||
|
"\\item 5.5\n",
|
|||
|
"\\item 2.5\n",
|
|||
|
"\\item 1\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 10\n",
|
|||
|
"2. 8.5\n",
|
|||
|
"3. 7\n",
|
|||
|
"4. 5.5\n",
|
|||
|
"5. 2.5\n",
|
|||
|
"6. 1\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 10.0 8.5 7.0 5.5 2.5 1.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"f[-5]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 69,
|
|||
|
"id": "93988d2c-458c-490b-b2da-10281184f949",
|
|||
|
"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>8.5</li><li>5.5</li><li>2.5</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 8.5\n",
|
|||
|
"\\item 5.5\n",
|
|||
|
"\\item 2.5\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 8.5\n",
|
|||
|
"2. 5.5\n",
|
|||
|
"3. 2.5\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 8.5 5.5 2.5"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"f[-seq(1,7,2)]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 70,
|
|||
|
"id": "95a6e8a0-7bb7-4ccd-9fdf-513cd867940b",
|
|||
|
"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>4</li><li>2.5</li><li>1</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 4\n",
|
|||
|
"\\item 2.5\n",
|
|||
|
"\\item 1\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 4\n",
|
|||
|
"2. 2.5\n",
|
|||
|
"3. 1\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 4.0 2.5 1.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"f[f<5]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "e0711b80-ccb4-4ea3-916a-ab216f198c53",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"W przypadku macierzy podajemy po przecinku indeksy interesujących nas wierszy i kolumn, np. polecenie `A[2,3]` zwróci element z drugiego wiersza i trzeciej kolumny. Jeśli przed lub po przecinku nic nie wpiszemy, to zostaną wybrane wszystkie elementy z danej kolumny lub wiersza."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 9,
|
|||
|
"id": "d3def94c-3bf3-46eb-99de-4943e811be27",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<table class=\"dataframe\">\n",
|
|||
|
"<caption>A matrix: 2 × 3 of type dbl</caption>\n",
|
|||
|
"<tbody>\n",
|
|||
|
"\t<tr><th scope=row>a</th><td>1</td><td>2</td><td>-4</td></tr>\n",
|
|||
|
"\t<tr><th scope=row>e</th><td>2</td><td>5</td><td> 8</td></tr>\n",
|
|||
|
"</tbody>\n",
|
|||
|
"</table>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"A matrix: 2 × 3 of type dbl\n",
|
|||
|
"\\begin{tabular}{r|lll}\n",
|
|||
|
"\ta & 1 & 2 & -4\\\\\n",
|
|||
|
"\te & 2 & 5 & 8\\\\\n",
|
|||
|
"\\end{tabular}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"\n",
|
|||
|
"A matrix: 2 × 3 of type dbl\n",
|
|||
|
"\n",
|
|||
|
"| a | 1 | 2 | -4 |\n",
|
|||
|
"| e | 2 | 5 | 8 |\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" [,1] [,2] [,3]\n",
|
|||
|
"a 1 2 -4 \n",
|
|||
|
"e 2 5 8 "
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"A"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 10,
|
|||
|
"id": "fcd91e12-4a41-40a5-87a9-65e033f0931b",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<strong>e:</strong> 8"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\textbf{e:} 8"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"**e:** 8"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"e \n",
|
|||
|
"8 "
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"A[2, 3]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 11,
|
|||
|
"id": "0e48fdc3-d997-4969-9387-667c8d40a7b9",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<style>\n",
|
|||
|
".dl-inline {width: auto; margin:0; padding: 0}\n",
|
|||
|
".dl-inline>dt, .dl-inline>dd {float: none; width: auto; display: inline-block}\n",
|
|||
|
".dl-inline>dt::after {content: \":\\0020\"; padding-right: .5ex}\n",
|
|||
|
".dl-inline>dt:not(:first-of-type) {padding-left: .5ex}\n",
|
|||
|
"</style><dl class=dl-inline><dt>a</dt><dd>2</dd><dt>e</dt><dd>5</dd></dl>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{description*}\n",
|
|||
|
"\\item[a] 2\n",
|
|||
|
"\\item[e] 5\n",
|
|||
|
"\\end{description*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"a\n",
|
|||
|
": 2e\n",
|
|||
|
": 5\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"a e \n",
|
|||
|
"2 5 "
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"A[, 2]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 12,
|
|||
|
"id": "c642bf34-af05-4181-9491-873a2a5150eb",
|
|||
|
"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>2</li><li>5</li><li>8</li></ol>\n"
|
|||
|
],
|
|||
|
"text/latex": [
|
|||
|
"\\begin{enumerate*}\n",
|
|||
|
"\\item 2\n",
|
|||
|
"\\item 5\n",
|
|||
|
"\\item 8\n",
|
|||
|
"\\end{enumerate*}\n"
|
|||
|
],
|
|||
|
"text/markdown": [
|
|||
|
"1. 2\n",
|
|||
|
"2. 5\n",
|
|||
|
"3. 8\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
"[1] 2 5 8"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"A[2, ]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "bec2c9a1-9b1c-47e9-a2d0-c9d628cb25c6",
|
|||
|
"metadata": {
|
|||
|
"tags": []
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## Operatory logiczne\n",
|
|||
|
"\n",
|
|||
|
"* `x==y` - prawda, jeśli `x` jest równe `y`;\n",
|
|||
|
"* `x!=y` - prawda, jeśli `x` jest różne od `y`;\n",
|
|||
|
"* `x&y` - koniunkcja `x` i `y` (jeśli `x` i `y` są wektorami, to porównywane będą wszystkie odpowiadające sobie współrzędne);\n",
|
|||
|
"* `x|y` - alternatywa `x` i `y` (jeśli `x` i `y` są wektorami, to porównywane będą wszystkie odpowiadające sobie współrzędne);\n",
|
|||
|
"*`!x` - negacja `x`."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "e6e25597-4bb9-4063-a92a-f98c15a15a5a",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"a = c(1, 0, 0, 1)\n",
|
|||
|
"b = c(1, 1, 0, 0)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "7b1015b2-8726-47fe-8907-f4f8e49fa336",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"a&b"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "434dae7b-40a5-4c67-860d-66260160f143",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"a|b"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "d2a46b15-f74f-478f-a05f-b2608910f760",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"!a"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "fa5f6e01-cf64-430c-8793-52745b69455e",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Instrukcja warunkowa i pętle\n",
|
|||
|
"\n",
|
|||
|
"Poniżej pokażemy na przykładach, jak możemy tworzyć pętle i instrukcje warunkowe.\n",
|
|||
|
"\n",
|
|||
|
"Instrukcja `if ... else`:\n",
|
|||
|
"\n",
|
|||
|
"```if (warunek) {instrukcje_1} else {instrukcje2}```\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "30e484d1-b54f-4ba5-bf87-4a05d364bdae",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"# Instrukcja warunkowa porównująca dwie liczby\n",
|
|||
|
"a = 5\n",
|
|||
|
"b = 3\n",
|
|||
|
"if (a>b) {\n",
|
|||
|
" print('a jest większe od b')\n",
|
|||
|
" } else {\n",
|
|||
|
" print('b jest większe lub równe a')\n",
|
|||
|
" }"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "bf367e0f-2394-4a52-8025-0b3baf58ff26",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Pętla `for`:\n",
|
|||
|
"\n",
|
|||
|
"```for (iterator in kolekcja) {instrukcje} ```"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "1942d50a-a722-4023-84dc-cb432ec96390",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"# Pętla for wyliczająca kwadraty kolejnych liczb z wektora x\n",
|
|||
|
"x = 1:10\n",
|
|||
|
"for (i in x) {\n",
|
|||
|
" print(i^2)\n",
|
|||
|
" }"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "21da6723-af26-4f43-8d46-5ec1f07b9854",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Pętla `while`:\n",
|
|||
|
"\n",
|
|||
|
"```while (warunek) {instrukcje} ```"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "51ee9a79-c0a5-4b6f-9d1d-d6e95919c5e9",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"# Pętla while wyliczająca kwadraty kolejnych liczb z wektora x\n",
|
|||
|
"i = 0\n",
|
|||
|
"while (i<10) {\n",
|
|||
|
" i = i+1\n",
|
|||
|
" print(i^2)\n",
|
|||
|
" }"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "4cfe04fe-d5ee-440a-bd1b-8a99cc9030d9",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Funkcje\n",
|
|||
|
"\n",
|
|||
|
"* Funkcje możemy zdefiniować w następujący sposób:\n",
|
|||
|
"\n",
|
|||
|
"`nazwa<-function(x1, x2, ..., xn) {instrukcje}`,\n",
|
|||
|
"\n",
|
|||
|
"gdzie $x1,x2,\\ldots, xn$ są argumentami funkcji.\n",
|
|||
|
"* Możemy podać dowolną liczbę argumentów, ale każdy z nich powinien mieć unikalną nazwę. Możemy też podać dla nich wartości domyślne, podając wartość po nazwie każdego argumentu: \n",
|
|||
|
"\n",
|
|||
|
"`function(x1=wartosc1, x2=wartosc2, ..., xn=wartoscn) {instrukcje}`.\n",
|
|||
|
"\n",
|
|||
|
"* W przypadku, gdy funkcję da się zapisać za pomocą pojedynczej instrukcji, nawiasy klamrowe można pominąć, tzn. stosujemy schemat:\n",
|
|||
|
"\n",
|
|||
|
"`nazwa<-function(x1, x2, ..., xn) instrukcja`.\n",
|
|||
|
"\n",
|
|||
|
"* Wynikiem działania funkcji będzie wartość wyznaczona w ostatniej linijce instrukcji lub argument instrukcji `return()`.\n",
|
|||
|
"\n",
|
|||
|
"* Aby wywołać funkcję należy podać jej nazwę, a następnie w okrągłych nawiasach podać wartości jej argumentów. Jeśli chcemy podać wartości tylko dla wybranych argumentów (a dla pozostałych zastosować wartości domyślne), to powinniśmy podać nazwę argumentu, a następnie po znaku `=` podać jego wartość."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 13,
|
|||
|
"id": "943c0244-1d30-484b-beb3-da7912c58918",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"pole<-function(a=2, b=3) a*b\n",
|
|||
|
"#definicja funkcji obliczającej pole prostokąta a wymiarach axb"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "b49d0759-b75d-408c-b9d8-0ed6c3e94afb",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"pole() #zwraca pole prostokąta o domyślnych wymiarach tzn. 2x3"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "6136a35d-3813-46e2-b1ac-7184d5a9bf1f",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"pole(3, 4) #zwraca pole prostokąta o wymiarach 3x4"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "c3838a75-6cb6-4c44-af70-d7456917fd87",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"pole(b=5) #zwraca pole prostokąta o wymiarach 2x5"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "a59d8644-3521-46c7-9ca1-fd563da5f000",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Wykresy i diagramy\n",
|
|||
|
"\n",
|
|||
|
"Program R oferuje bardzo szerokie możliwości wizualizacji danych. Podstawowa funkcja generująca wykresy to:\n",
|
|||
|
"\n",
|
|||
|
"`plot(x ,y, ...)`,\n",
|
|||
|
"\n",
|
|||
|
"gdzie `x` i `y` to wektory zawierające odpowiednio pierwsze i drugie współrzędne punktów, które chcemy umieścić na wykresie. Jeśli podamy tylko wektor `y`, to domyślnie zostanie przyjęte, że wektor `x` to kolejne liczby naturalne od $1$ do $n$, gdzie $n$ to długość wektora `y`. W miejscu '...' możemy podawać najróżniejsze parametry związane z wyglądem wykresu. Wśród najważniejszych opcji, które możemy zdefiniować są:\n",
|
|||
|
"\n",
|
|||
|
"* `type` - kontroluje typ wykresu. Przykładowe opcje to:\n",
|
|||
|
" * `p` - wykres punktowy (jest to opcja domyślna),\n",
|
|||
|
" * `l` - wykres liniowy,\n",
|
|||
|
" * `b`, `o` - wykresy liniowo-punktowe (różnica polega na sposobie łączenia punktów z liniami).\n",
|
|||
|
"* `xlim`, `ylim` - pozwalają ustalić graniczne wartości odpowiednio na osi $OX$ i $OY$ wykresu,\n",
|
|||
|
"* `main` - pozwala dodać główny tytuł do wykresu,\n",
|
|||
|
"* `sub` - pozwala dodać podpis / podtytuł do wykresu,\n",
|
|||
|
"* `xlab`, `ylab` - pozwalają dodać nazwy osi,\n",
|
|||
|
"* `col` - pozwala ustalić kolory punktów / linii umieszczanych na wykresie. Jako argumenty możemy podawać nazwy kolorów (np. `blue`) lub liczby naturalne,\n",
|
|||
|
"* `pch` - pozwala ustalić typ (kształt) punktów używanych na wykresie. Poniżej przedstawiono $25$ podstawowych typów punktów, wraz z odpowiadającymi im numerami,\n",
|
|||
|
"![Typ punktów](punktyR.png)\n",
|
|||
|
"* `cex` - pozwala ustalić wielkość punktów,\n",
|
|||
|
"* `lty` - pozwala ustalić typ linii (dla wykresów liniowych). Typ można podać słownie lub za pomocą odpowiedniej liczby naturalnej. Podstawowe typy linii to (po nazwie podajemy też przypisaną jej liczbę naturalną):\n",
|
|||
|
" * `solid` (1) - linia ciągła (jest to opcja domyślna),\n",
|
|||
|
" * `dashed` (2) - linia kreskowana,\n",
|
|||
|
" * `dotted` (3) - linia kropkowana.\n",
|
|||
|
"* `lwd` - pozwala ustalić szerokość linii. \n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 104,
|
|||
|
"id": "a0431b47-a9b2-4a8f-ad64-e2dcc4a87dac",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAIAAAByhViMAAAACXBIWXMAABJ0AAASdAHeZh94\nAAAgAElEQVR4nOzdd4AU9cHw8dnjKr1JEwEBKYqCHVEREwsKPooFUWN7IraYx54oAfURAxY0\najCoxBjsxhgVxDxGY40FE0VUiiASCwiK0pGDu9v3j32eec87uMbd7d3vPp+/7mZnZ3/Mzt5+\nmZ2ZTSSTyQgAgPovI90DAACgegg7AIBACDsAgEAIOwCAQAg7AIBACDsAgEAIOwCAQAg7AIBA\nCDsAgEAIOwCAQAg7AIBACDsAgEAIOwCAQAg7AIBACDsAgEAIOwCAQAg7AIBACDsAgEAIOwCA\nQAg7AIBACDsAgEAIOwCAQAg7AIBACDsAgEAIOwCAQAg7AIBACDsAgEAIOwCAQAg7AIBACDsA\ngEAIOwCAQAg7AIBACDsAgEAIOwCAQAg7AIBACDsAgEAIOwCAQAg7AIBACDsAgEAIOyjfnDlz\nEluTlZXVq1ev4cOHz5gxIy0Du+CCC1IjOfjgg8uY7ZRTTknNdswxx1TXQz///PPxevj222+r\na7H1WgWfDiLrCmqMsIOqKygoWLRo0cyZM//jP/5j1KhR6R4OBKioqOiY//P666+nezhQ12Wm\newAQiMcff3z48OE/+clP0j0QCEoymXz22WdTP3t9QbnssYPKueOOOwoKCgoKCrZs2fLvf//7\n2muvjW+aMGFCGgcGAMIOKqfR/8nMzOzatet111131FFHpW5atGhRQUFBeocHIVm0aNHbb79d\n/NdZs2atX78+jUOCOk7YwfYaNGhQ6oeCgoLPPvssiqL//u//Th0Yvssuu0RR9NRTT+255569\ne/eOoujbb7/d6nkYscLCwrPPPjv1c2Zm5qpVq4o/1nHHHZe66fDDD9/WeO655554affff38Z\nI9+yZcv9999/6KGHduvWLTc3t0uXLgceeOCdd95Z+o3zk08+GTly5A477NCuXbvjjjvu6aef\nLnuxt91227HHHtu9e/cWLVoMGjTo3HPP/fDDD+MZhgwZUvpkjhtuuCEe9ooVK1IT33777Xji\nm2++uT1rJi0PGm3t6Shj80iZM2fOOeecs/feezdt2rRnz54nn3zym2++WWKxyWTyqaeeGjp0\naI8ePfLy8nr06HH44Yc/+OCD5f7XYvTo0alHP/TQQzds2HDppZd27tw5Ly+vX79+N9xwQ35+\n/rZmLj79vvvuS03PysqKJxb/dxUVFd1666277bZbXl5et27djj/++AULFpQ9sK2uqzFjxhx0\n0EHxDOPGjRs4cODcuXPjKXVzY4N0SgLlef/99+OXzOTJk0vcOn78+PjWr7/+OplMXnfddalf\ne/bs+dBDDyUSiSiKunXrlkwmV65cWfZLsqCg4IUXXoh/feSRR+IH2rx5c7NmzVLTp06dmkwm\nzz///NSvBx10UGqeF198MTPzf4+dveGGG1IT4xM7jjrqqOuuu27Dhg3JZHLTpk0DBw7c6hh2\n3333devWxY/78ssvt27dusQ8J510UvzzypUr45k/+OCDPfbYo/Qys7Kyrr322qKiomQyOXHi\nxNTE1q1bp6Ykk8nhw4fHM8+YMSM18fbbb09NadmyZaXWTGm18KAVfDrK2DySyeRtt92WnZ1d\negX+4he/iIddVFR07LHHlp4niqK99tqr+HNX2jnnnBMPsngzpeyxxx4ff/xx6ZmHDBlSfCG/\n//3vU9MzMzPjifG/q0ePHqecckqJJefk5MyZMyeeuYLr6sQTTyz9b3z77bdTt9bZjQ3SSNhB\n+coOu2HDhqVuat68eWpK/A7Xvn37Nm3apH5OvXOvWbNm6A8Vr6ucnJzCwsKCgoIOHTqkppx6\n6qnxA73yyivx+9a3336bLPXu+PHHH7dq1So15YILLojvGIddqiHWr1+fTCavuuqq+HH79Olz\nyCGHtG/fPp5yzTXXpO77zTffxG9jURR16NChadOmJd5H47DbuHFj9+7d4+ldunTZd999c3Jy\n4il/+MMfksnk7Nmz4ykLFixI3XeHHXaIJ44dOzY1Me6Dk046KZlMVnzNlFYLD1rBp6OMzeP5\n55+PxzNo0KCzzz573333jadMmjQptYQ77rgjntirV6/jjz9+4MCBqSc3iqKzzjprq2sgJW61\n1PyJRKJbt25xUUVRdNhhh5WeuVJhFy+/Y8eOxZd85JFHxjNXcF2l1n+8hMceeyyeXpc3Nkgj\nYQfl21bYLVu2rPjuuvgdsfg7XHZ29gUXXDB16tTi/+mPbdmy5cc//nE884MPPpiafvHFF6em\ntGrVasuWLamJcYodffTRqSnF3x2/++671Ed7URSNGDGisLAwfpTjjjsufiu65ZZbUhP79u2b\nmjhu3Lh4zvh4waFDh6amXHrppakpTZo0mT59emrMv/zlL6Ni4rAbO3ZsakpGRsZ9990Xr6V9\n9tknNb1t27bfffddUVFR/JaZevf99NNPU7+mauOII45I3Td+546XVsE1U1otPGgFn45tbR4F\nBQW77rpranpcG8XXatOmTVMlET9Np59+ejzb3XffnZpYfNdUaXGrRVG0xx57/Pvf/04mk6tW\nrTriiCPi6W+99VaJmSsbdiNGjPjmm2+SyeTKlSvjNo3/51PxdZXcdtjV5Y0N0kjYQfmKh10Z\n3njjjdT8xd/h/vKXv5Sx5HPPPTee81e/+lU8fdasWfH0V199NTVxzz33TE154IEHUlPid8f9\n9tsvPgpq0KBB33//fbyoCy+8MF7UsGHDUhOLiooe+z+pN+BkMrl27drBgwen5txnn31SE+Pd\ndfE+vBKDiYqFXZ8+fVJTiu/hSCaTH374Ybw/KbVCzjzzzNSv55xzTjKZfOSRR+IRRlHUsmXL\noqKir7/+On6IL7/8slJrZqtq+kEr8nQkt715fPTRR6mJGRkZq1atiqevXbs23u/16KOPJpPJ\nvffeO/XrjjvuOGXKlM8//zyZTG7cuPGV/xNXSGnFw+7dd9+Npy9fvjwvLy81ffz48SVmrlTY\nZWdnF/84+MEHHyy9qVRwXSW3HXZ1fGODdHHyBFSDRCJx1VVXxWdRxJo1azZixIht3eu22267\n9957Uz+fcMIJxXf+7bfffj169Ej9nLqI14oVK1J9mZOTU/r4qnfeeefll19O/ZyZmZmbmxvf\n9Lvf/a5JkybxOOMfTj755BNOOKFz585TpkwZOXLkgAEDdthhh9dee634YpcuXbpu3brUz8cf\nf3zxm0ofRLV58+ZPPvlkqzP369cv3iUzf/78KIqGDh2a+jV1WkDqHbRDhw4jR46Momj16tWp\n8x9T8+yxxx477rhj1dZMcbX2oGU8HcWV2Dzi0wuKiopatWoVH8jfvHnzOG5S8xx99NGpX5cu\nXXrBBRd06dKld+/el19+eWr32CGHHFL8A9Bt2Wmnnfbaa6/41/bt28cb8MKFC8u9exk6d+5c\n/PP6eIdZFEWlz+2o4Loqoe5vbJAuwg62S+fOnY855piZM2fGx2gX165du23d8dlnn73yyitT\nP++1114PPPBAXF0pp556auqH1PeVPf/888lkMoqio48+unnz5mUM6bXXXnv88cfjX6dNm7bV\nbxJ7//33+/fvf9BBB11zzTV//vOfN2zYcNxxx8Wf8aV8/PHH8c/xu13KzjvvXGKBS5cujd+2\nS8wcRVHnzp1TP6Q+CDv88MMzMjKiKJo/f/6qVatSb6uDBg3af//9U7PNmjUrfq+N35hTqrxm\n0vKgJZ6O4kpsHqlTqsv23XffRVE0duzYMWPGFD+jZeHChVOmTDnxxBM7duwY704rW6dOnUpM\niZ+1+ETRqkmt5FiJDbsMZayrEur+xgbpIuygckqcPPHFF19Mnz69RA/FtvWWNmfOnFNOOaWo\nqCiKok6dOk2fPr1x48Yl5onfURYsWLB48eL4sPqTTz55q8vcdddd99tvv9TPV1555caNG1M/\nn3HGG
|
|||
|
"text/plain": [
|
|||
|
"Plot with title “Przykładowy wykres punktowy”"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"image/png": {
|
|||
|
"height": 420,
|
|||
|
"width": 420
|
|||
|
}
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"#Zaczniemy od narysowania prostego wykresu punktowego\n",
|
|||
|
"x = seq(-2, 1, 0.5)\n",
|
|||
|
"y = c(1, 0, 1, 2, 3, -1, 2)\n",
|
|||
|
"plot(x, y, pch=2:8, cex=2, col=1:7, main='Przykładowy wykres punktowy', sub='Różne rodzaje punktów')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 105,
|
|||
|
"id": "6ba01a91-0629-498c-8ff7-e06026049f28",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAIAAAByhViMAAAACXBIWXMAABJ0AAASdAHeZh94\nAAAgAElEQVR4nOzdd2AUZeLG8SchBEIHIYTeQihCEkRA6SgoiCgKR5ETUJBDLKjI2RAQQU4F\nPBAplqOoNBVBwFNOgVAURI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DF8P65TqzJ08eVLSsGHDXn75ZfczWnbt2jV16tSuXbuWK1fu\nww8/zPJ5rov1ptkyfFGvxfe/D4BfoNgBnpXh5ImDBw9+9dVXGfqQ7Vp/AmNjY3v27Jmeni6p\nfPnyX331VaFChTI8xv5z9dtvv+3du9deVt+9e/erPmfdunUbN25sjYcOHXrhwgVr3Lt37ysf\nfPny5S5duuzYsUNSjx49Dh8+vHv37nnz5kVHR7s/zH2e5vDhw+4/smfybBUqVLAnig4dOpTh\npwkJCdagUqVKkm666SZrqZbL5YqJibGWzzdt2jQiIqJ48eKSfvrpp/Xr11u/kuHtvd53xubN\nF73Wx+Euw9fDemcklShRYu01PPPMM5KCg4PHjBlz9OjRmJiYF198MSoqyn6Ss2fPZriYiCm+\n/30A/ALFDvB1R44c6dSpk3WtuJCQkMWLF185nyGpdu3a9lKhxYsXL1++XFKhQoXcLwNhCw0N\n/fbbbydMmGBtHjx48B//+EcmGWJjY+316aNGjbLPh81QCOzjZZK+/PJL9x8tW7Ysw3MGBwfb\nB8UyP
|
|||
|
"text/plain": [
|
|||
|
"Plot with title “Przykładowy wykres liniowy”"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"image/png": {
|
|||
|
"height": 420,
|
|||
|
"width": 420
|
|||
|
}
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Jeśli zmienimy typ wykresu na liniowy, to podane punkty zostaną połączone łamaną\n",
|
|||
|
"plot(x, y, type='l', lty='dashed', lwd=3, col='green', main='Przykładowy wykres liniowy', xlab='argumenty', ylab='wartosci')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "94255033-2084-45e9-bd6c-d10e46a098e8",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"Jeśli chcemy narysować wykres funkcji, dla której znamy wzór, możemy też zastosować następujące polecenie:\n",
|
|||
|
"\n",
|
|||
|
"`curve(f, from=NULL, to=NULL, n, add=FALSE, ...)`,\n",
|
|||
|
"\n",
|
|||
|
"gdzie:\n",
|
|||
|
"\n",
|
|||
|
"* `f` - nazwa lub wzór funkcji,\n",
|
|||
|
"* `from`, `to` - minimalny i maksymalny argument, dla których będzie obliczana wartość funkcji,\n",
|
|||
|
"* `n` - liczba naturalna, która oznacza liczbę punktów, w których będzie obliczana wartość funkcji. Punkty te są rozmieszczone równomiernie w dziedzinie,\n",
|
|||
|
"* `add` - przyjmuje wartość `TRUE`, jeśli wykres ma być dorysowany do wcześniej istniejących wykresów i `FALSE` w przeciwnym przypadku.\n",
|
|||
|
"\n",
|
|||
|
"Podobnie, jak w przypadku polecenia `plot` w miejscu `...` można wpisać wiele różnych parametrów kontrolujących wygląd wykresu."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 120,
|
|||
|
"id": "472084d6-7c92-4b9a-b710-772b2f571252",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAIAAAByhViMAAAACXBIWXMAABJ0AAASdAHeZh94\nAAAgAElEQVR4nOzdd3xN9x/H8c9NIhHECiJmCJEg+NkNYm8q9i7amlW0qi21WrVKq1SrdNir\npUakpWqPxqqV2KMoNYKgIZLI/f1x9LhNJLmJm3zvvXk9H/6493vPPfd97z253vesazAajQIA\nAADb56A6AAAAACyDYgcAAGAnKHYAAAB2gmIHAABgJyh2AAAAdoJiBwAAYCcodgAAAHaCYgcA\nAGAnKHYAAAB2gmIHAABgJyh2AAAAdoJiBwAAYCcodgAAAHaCYgcAAGAnKHYAAAB2gmIHAABg\nJyh2AAAAdoJiBwAAYCcodgAAAHaCYgcAAGAnKHYAAAB2gmIHAABgJyh2AAAAdoJiBwAAYCco\ndgAAAHaCYgcAAGAnKHYAAAB2gmIHAABgJyh2AAAAdoJiBwAA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VKe4ksVezy58+v10r9m4CI\nzJw5U5+4W7du2qC2rtH8P67ndibzFwOFIY1mL11mvl+mkvpUNH9xsmw202J35swZfbKpU6dq\ng1mzZjXCynAeO7wog8Hw3nvv6UdR6Nzc3Nq2bZvUvT777LN58+Zpl9u3b2+68q969ere3t7n\nz58XkQ0bNgQGBt64cUPrly4uLon3r9q/f79+2cnJKWvWrPrVr776Knv27FFRUfLvqintQufO\nnePi4
|
|||
|
"text/plain": [
|
|||
|
"Plot with title “Przykładowe wykresy funkcji matematycznych”"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"image/png": {
|
|||
|
"height": 420,
|
|||
|
"width": 420
|
|||
|
}
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Narysujemy wykres funkcji pierwiastek z x na przedziale [0, 10]\n",
|
|||
|
"curve(sqrt, from=0, to=10, n=50, col='blue', lty=2, ylim=c(-1,3), main='Przykładowe wykresy funkcji matematycznych', ylab='y')\n",
|
|||
|
"\n",
|
|||
|
"# Następnie dorysujemy wykres funkcji f(x) = 1/50*x^2-1\n",
|
|||
|
"curve(1/50*x^2-1, from=0, to=10, col='red', lty=3, add=TRUE)\n",
|
|||
|
"legend(0, 2.5, c('sqrt(x)', '1/50*x^2-1'), col=c('blue', 'red'), lty=c(2,3))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "37a17b8d-bbb3-487f-a1f7-fb2159c2a2b4",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"W R możemy też stworzyć wykresy słupkowe. Służy do tego następujące polecenie:\n",
|
|||
|
"\n",
|
|||
|
"`barplot(height, names.arg=NULL, horiz=FALSE, ...)`,\n",
|
|||
|
"\n",
|
|||
|
"gdzie `height` oznacza wysokość kolejnych słupków, a `names.arg` etykiety kolejnych słupków. Jeśli `horiz` ma wartość `TRUE`, słupki rysowane są poziomo, w przeciwnym przypadku słupki rysowane są pionowe. Ponownie możemy też podać wiele innych argumentów wpływających na wygląd wykresu."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 128,
|
|||
|
"id": "4ef6a173-0772-4c1d-a63f-e571de4042aa",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAIAAAByhViMAAAACXBIWXMAABJ0AAASdAHeZh94\nAAAgAElEQVR4nO3dd5wU9cH48bmDO0GqVFEQlKpwUiKKIKBJbCg2rBAfsESsvxhSLBErCQlP\nYsRgxWASVDTGikgUo48Ng2kSQKRZEAuiHEWkHbe/P/aVeW3uYNk97tjbr+/3X3ezc3PfnZ2d\n/dzs7FxBIpGIAADIf4W5HgAAANVD2AEABELYAQAEQtgBAARC2AEABELYAQAEQtgBAARC2AEA\nBELYAQAEQtgBAARC2AEABELYAQAEQtgBAARC2AEABELYAQAEQtgBAARC2AEABELYAQAEQtgB\nAARC2AEABELYAQAEQtgBAARC2AEABELYAQAEQtgBAARC2AEABELYAQAEQtgBAARC2AEABELY\nAQAEQtgBAARC2AEABELYAQAEQtgBAARC2AEABELYAQAEQtgBAARC2AEABKJurgcAAJADK1as\nWLlyZRRFbdu2bd26da6HUz3y9YjdypUrC/5j7Nixaea85557krM1atRotw2vsksuuSQ5jIED\nB+ZwGBW88cYbRUVFRUVF559/fprZ1qxZ06xZs6Kiov79+2/atGm3DS+Hqv0u15LtMCv5OObK\ncngvUndTle255569evW65pprvvrqqxoaQC15BHfb3m/u3LnbXdVFRUVdunQ58cQTp0+fXqMD\n2HXPPfdcPOwvvvgi18PJyK6POastpHq36iFDhhxyyCFnnXVW3brhHOfK17CjWkyYMKGsrKxf\nv3533313mtnuvPPO0tLSvffe+7HHHqtXr95uG14OfQ3vMrvZxo0b586d+/Of/7xfv35bt27N\n9XBCVlZWtmTJkhkzZpx00klnn312rodDbfHss8/OmzevSZMm06dPb968edUWUl5ePvQ/Xn31\n1eodYdUIu6+vRYsWPfXUUx07dnziiSeKi4t3NNvGjRsnTpzYoEGDp59+uk2bNrtzhLnyNbzL\n5NC8efNuu+22XI/i6+KRRx554IEHcj0KaoUJEybUqVPnj3/844EHHljlhSQSiWf+4+OPP67G\n4VVZ+GF30UUXlZWVlZWVrVmzJtdjqV0WLlx4wQUXPPPMMy1atEg/20knnfToo4/27t17t40t\nt2riLufjdpiPY661rr322rL/2Lp16xdffHHnnXfGtz799NM5HFuQJk6cGK/t999//4Ybbohv\n+tnPfpbDgbGLqmu/tGnTpnPOOWfmzJnHHHNMdY2tlgjnTeUdKSgoqFOnTq5HURudcsopp5xy\nyk5n69Onz+TJk3fDeGqPmrjL+bgd5uOYa63CwsLUldmsWbNLLrnkkUceefnll6MoWrBgQe6G\nFqY6derEK7x9+/Y33njjm2++OXPmzCiKlixZUlZWFtI5VV8r1bVfqlev3ujRo3dxIUuWLPns\ns89Sv50zZ0737t0bNmy4i0veFeEfsUtzomVpaelVV131rW99q0WLFm3atDnqqKN+/etfxye7\nfPHFF2lOfC4oKNi2bVu8qLlz51544YXf+MY3GjZs2KlTp7POOmv27Nk7GtKqVau+973v9enT\np0GDBj179vz1r3+dSCRSZ7jpppuSv6Jz587l5eW/+tWvunfvXr9+/Q4dOpx22mnvvPNO5WVu\n3br11ltvPfnkkw844IAmTZr079//oosumjdvXuU5E4nEE088cdxxx3Xs2LF+/fodO3Y8+uij\np06dWlZWltX6Se+rr766+uqrDz744EaNGh199NELFy6MH4jDDz98u/c0iqInnniid+/eXbt2\njaLou9/9bvKmo446KnXJv/3tb+MTouOJqTNv2LDh+9//ftu2bevXr9+jR49x48Zt3rw5kzHv\n9C4feeSRyd8ydOjQ+EfGjRsXbxLJT1dFUfTXv/41npjcEmrJdpjVppVmzDvd3qq8rs4777zk\n13Xr1i0tLU39paecckrypqOPPjrDtVfZ5MmTe/bsueeee+6///7nn3/++++/v6M5q7D+s9W+\nffvkFwUFBfHErVu33n///UcddVSHDh3q1au33377DRgw4Pbbb//yyy8r/Hj13vesnnFV2EdV\nEG9dBQUF999/f7YDqIL+/fsnvygrK/vggw+itPufKIMHYld2CElLly4988wzW7Zs2apVq1NO\nOeXJJ59MM/4Md/JV2Blm/vJRQ2NOtdPXxzT7perdAUYZvFxee+21RxxxRDz/2LFj+/Xrt2DB\ngl3ZNjLfA+xQIj99+umn8V247rrr0swZfyygYcOGqdP/8pe/7LPPPpVXSNeuXVeuXJlIJD7/\n/PP0q66srCy5qFtvvXW756j9+Mc/Li8vT85z8cUXJyeWlJR06dKlwpzDhg376quv4rHdeOON\nyekdO3Y855xzKsy8xx57zJ07N/W+/Pvf/z744IMrD6CoqOiGG26Ix5BIJMrLy08++eTt3p0+\nffqsX78+8/WTxooVK+KdY1KrVq0uu+yy5Nf9+vWrfE87der0wAMPJF/eOnTokEgkLrzwwuRN\nRx55ZOrC77vvvuT0unXrxhPjmY844ojUp1nSwQcfvGjRovRjzuQujx8/PjmlWbNm8Vo98cQT\n4zmnT5+enBifMtW0adPkdlJLtsOsNq0djTmT7a3K62rWrFnxPA899FD8S7ds2RLvxydPnpzh\n2qtwL6688soKc7Zo0eLTTz9Ns1Vkvv4r2+luKv4M4OGHH56csmnTpn79+m33F5WUlGT7DM3q\nvmf1jMtqQ4r3fkcccURyygsvvBAfMBs3blwVBrBdb731VjyGSZMmVbj1lltuiW/97LPPEmn3\nP5k8ELuyQ0gkEi+99FKzZs0qLPyMM86Iv/7888/jwWe+k892Z5j5kmtuzFm9Pu5ov1TtO8BM\nXi5PP/30yrf+9a9/rfK2kfkeII2vadh98cUX8dZZVFTUp0+f1LOpjjnmmEQisXbt2uP+W+rq\n3mOPPbZt25ZIJJ577rl4Yv/+/c8777y+ffvGU375y18mf2O84SYVFBR06NAh9b2A7373u/Hw\n4o0vnrlNmzapMx977LHxzF999dUBBxwQ37Tffvv17dt3jz32iKdMmTIlnnnixInx9C5dupx2\n2mn9+vWLjxaMGjUq8/WTxkknnRTP3KpVqwYNGqTene2GXevWreMPJe1K2CXvS+XV++1vfzv9\nmDO5y//617/iKe+8807yB1u2bBlPjDfFeJdxxhlnJKfUku0wq01ru2POcHur8roqKyvbe++9\nk1OGDx8e/97/+7//i1fUF198keHaS70X8V1u3bp16hGy8847L82GkeH63640u6m1a9fee++9\n8a33339/cvrVV18dT+zWrdvgwYNTr611/fXXZ77lZHvfqxZ28ZLTbEgVwm7RokV77bVXcsol\nl1xStQFsV/qwO+GEE5I3NW7cuMK9qLz/yeSB2JUdwqpVq1IPOO29996V37yLIymrnXxWO8Os\nllxzY87q9XG7+6Wa2AFm+HKZ+mbXww8/nJxY5W0jwz1Ael/TsLviiiuSE1u0aDFv3rzkxIcf\nfjhe5ttvv11hOVu3bv3Wt74VzzB16tREIlFWVnbQQQdVHsZ1110X/9Lki1Dqhtu9e/dly5Yl\nEonVq1fHbyoVFRV98MEHyR9P3fhOPfXUVatWJRKJzz//PN5S4x1T6u8qLCz87W9/m5z48ccf\nH3LIIfF9XL16dXL68ccfn5x47rnnVl5F8d8WVVg/sUcffTSe7bbbbisvL9+yZUu8wGgHYRdF\nUXFx8SWXXDJ58uTkcZqqhV0URQcffPD777+fSCRKS0tTz4p94403djTmDO9yeXl53BzJvdK7\n776b/Db5bI9fUOM9WvyI1JLtMKtNa7tjznB725V19b3vfS85Za+99tq6dWtyYry/GzJkSFZr\nLzVuBgwY8OGHHyYH07Fjx+TEHj16pNkwMln/O5K6m0rj0ksvjX8k/nTe2LFj44nx0/a4446r\nufte5
|
|||
|
"text/plain": [
|
|||
|
"Plot with title “Liczebność grup ćwiczeniowych z Rachunku Prawdopodobieństwa”"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"image/png": {
|
|||
|
"height": 420,
|
|||
|
"width": 420
|
|||
|
}
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Narysujmy wykres słupkowy przedstawiający liczebności grup ćwiczeniowych z Rachunku Prawdopodobieństwa\n",
|
|||
|
"licz = c(18, 24, 21, 21)\n",
|
|||
|
"grupy = c(1, 11, 12, 13)\n",
|
|||
|
"barplot(licz, names.arg=grupy, col=10:13, main='Liczebność grup ćwiczeniowych z Rachunku Prawdopodobieństwa')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "b6f63bf3-7328-400c-8024-588b81b45124",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Literatura\n",
|
|||
|
"\n",
|
|||
|
"* Marek Gągolewski, *Programowanie w języku R. Analiza danych, obliczenia, symulacje.* Wydawnictwo Naukowe PWN 2014. \n",
|
|||
|
"* Przemysław Biecek, *Przewodnik po pakiecie R*, GiS, 2017 (pierwsze rodziały tej książki są dostępne na [stronie autora](http://www.biecek.pl/R/PrzewodnikPoPakiecieRWydanieIVinternet.pdf)).\n",
|
|||
|
"* Wiele użytecznych materiałów można też znaleźć na następującej [stronie](https://cran.r-project.org).\n",
|
|||
|
"\tW szczególności, można znaleźć tam [krótkie wprowadzenie do R w języku polskim](https://cran.r-project.org/doc/contrib/wprowadzenie\\_do\\_R.pdf)."
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"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.2.1"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 5
|
|||
|
}
|