Skip to content

Instantly share code, notes, and snippets.

@PatrickRWright
Created August 18, 2020 07:35
Show Gist options
  • Save PatrickRWright/af63b0441727a0c41bf78347e7028687 to your computer and use it in GitHub Desktop.
Save PatrickRWright/af63b0441727a0c41bf78347e7028687 to your computer and use it in GitHub Desktop.
Created on Skills Network Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Merging/Joining data.frames in base R and with dplyr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First off we will build a dataset to work with. The data consists of several imaginary medical data forms. A baseline form, a pyschologocal form, a sports form and a medication form. the first three (baseline, psych, sport) forms contain only unique IDs. The forth form can include IDs more than once. If you are not interested in the data generation process you can skip forward to **\"This is where we start to perform merging/joining\"**."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"library(dplyr)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"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>'Pat-5611'</li><li>'Pat-5517'</li><li>'Pat-1591'</li><li>'Pat-4630'</li><li>'Pat-3985'</li><li>'Pat-3649'</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 'Pat-5611'\n",
"\\item 'Pat-5517'\n",
"\\item 'Pat-1591'\n",
"\\item 'Pat-4630'\n",
"\\item 'Pat-3985'\n",
"\\item 'Pat-3649'\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 'Pat-5611'\n",
"2. 'Pat-5517'\n",
"3. 'Pat-1591'\n",
"4. 'Pat-4630'\n",
"5. 'Pat-3985'\n",
"6. 'Pat-3649'\n",
"\n",
"\n"
],
"text/plain": [
"[1] \"Pat-5611\" \"Pat-5517\" \"Pat-1591\" \"Pat-4630\" \"Pat-3985\" \"Pat-3649\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# reproducibly create 1000 patient IDs\n",
"set.seed(1337)\n",
"id_num <- sample(x = 1000:9000, size = 1000, replace = FALSE)\n",
"id <- paste0(\"Pat-\", id_num)\n",
"head(id)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 5</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id</th><th scope=col>gender</th><th scope=col>age</th><th scope=col>weight</th><th scope=col>height</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>Pat-5611</td><td>female</td><td>72</td><td>54</td><td>153</td></tr>\n",
"\t<tr><th scope=row>2</th><td>Pat-5517</td><td>female</td><td>78</td><td>60</td><td>156</td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-1591</td><td>male </td><td>75</td><td>74</td><td>159</td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-4630</td><td>male </td><td>18</td><td>87</td><td>189</td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-3985</td><td>male </td><td>48</td><td>55</td><td>165</td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-3649</td><td>male </td><td>74</td><td>79</td><td>153</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 5\n",
"\\begin{tabular}{r|lllll}\n",
" & id & gender & age & weight & height\\\\\n",
" & <fct> & <fct> & <int> & <int> & <int>\\\\\n",
"\\hline\n",
"\t1 & Pat-5611 & female & 72 & 54 & 153\\\\\n",
"\t2 & Pat-5517 & female & 78 & 60 & 156\\\\\n",
"\t3 & Pat-1591 & male & 75 & 74 & 159\\\\\n",
"\t4 & Pat-4630 & male & 18 & 87 & 189\\\\\n",
"\t5 & Pat-3985 & male & 48 & 55 & 165\\\\\n",
"\t6 & Pat-3649 & male & 74 & 79 & 153\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 5\n",
"\n",
"| <!--/--> | id &lt;fct&gt; | gender &lt;fct&gt; | age &lt;int&gt; | weight &lt;int&gt; | height &lt;int&gt; |\n",
"|---|---|---|---|---|---|\n",
"| 1 | Pat-5611 | female | 72 | 54 | 153 |\n",
"| 2 | Pat-5517 | female | 78 | 60 | 156 |\n",
"| 3 | Pat-1591 | male | 75 | 74 | 159 |\n",
"| 4 | Pat-4630 | male | 18 | 87 | 189 |\n",
"| 5 | Pat-3985 | male | 48 | 55 | 165 |\n",
"| 6 | Pat-3649 | male | 74 | 79 | 153 |\n",
"\n"
],
"text/plain": [
" id gender age weight height\n",
"1 Pat-5611 female 72 54 153 \n",
"2 Pat-5517 female 78 60 156 \n",
"3 Pat-1591 male 75 74 159 \n",
"4 Pat-4630 male 18 87 189 \n",
"5 Pat-3985 male 48 55 165 \n",
"6 Pat-3649 male 74 79 153 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# create baseline form\n",
"gender <- sample(c(\"male\", \"female\"), size = 1000, replace = TRUE)\n",
"age <- sample(18:99, size = 1000, replace = TRUE)\n",
"weight <- sample(50:100, size = 1000, replace = TRUE)\n",
"height <- sample(140:220, size = 1000, replace = TRUE)\n",
"\n",
"form_bl <- data.frame(id, gender, age, weight, height)\n",
"head(form_bl)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 4</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id_psych</th><th scope=col>happy</th><th scope=col>therapist</th><th scope=col>partner</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>Pat-3279</td><td>yes</td><td>yes</td><td>yes</td></tr>\n",
"\t<tr><th scope=row>2</th><td>Pat-7052</td><td>yes</td><td>yes</td><td>no </td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-1492</td><td>no </td><td>no </td><td>yes</td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-3363</td><td>no </td><td>no </td><td>no </td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-2073</td><td>no </td><td>no </td><td>yes</td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-2835</td><td>no </td><td>no </td><td>no </td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 4\n",
"\\begin{tabular}{r|llll}\n",
" & id\\_psych & happy & therapist & partner\\\\\n",
" & <fct> & <fct> & <fct> & <fct>\\\\\n",
"\\hline\n",
"\t1 & Pat-3279 & yes & yes & yes\\\\\n",
"\t2 & Pat-7052 & yes & yes & no \\\\\n",
"\t3 & Pat-1492 & no & no & yes\\\\\n",
"\t4 & Pat-3363 & no & no & no \\\\\n",
"\t5 & Pat-2073 & no & no & yes\\\\\n",
"\t6 & Pat-2835 & no & no & no \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 4\n",
"\n",
"| <!--/--> | id_psych &lt;fct&gt; | happy &lt;fct&gt; | therapist &lt;fct&gt; | partner &lt;fct&gt; |\n",
"|---|---|---|---|---|\n",
"| 1 | Pat-3279 | yes | yes | yes |\n",
"| 2 | Pat-7052 | yes | yes | no |\n",
"| 3 | Pat-1492 | no | no | yes |\n",
"| 4 | Pat-3363 | no | no | no |\n",
"| 5 | Pat-2073 | no | no | yes |\n",
"| 6 | Pat-2835 | no | no | no |\n",
"\n"
],
"text/plain": [
" id_psych happy therapist partner\n",
"1 Pat-3279 yes yes yes \n",
"2 Pat-7052 yes yes no \n",
"3 Pat-1492 no no yes \n",
"4 Pat-3363 no no no \n",
"5 Pat-2073 no no yes \n",
"6 Pat-2835 no no no "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# create psych questionnaire form for 100 patients\n",
"id_psych <- sample(id, size = 100, replace = FALSE)\n",
"happy <- sample(c(\"yes\", \"no\"), size = 100, replace = TRUE)\n",
"therapist <- sample(c(\"yes\", \"no\"), size = 100, replace = TRUE)\n",
"partner <- sample(c(\"yes\", \"no\"), size = 100, replace = TRUE)\n",
"\n",
"form_psych <- data.frame(id_psych, happy, therapist, partner)\n",
"head(form_psych)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 3</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id_sport</th><th scope=col>sport_type</th><th scope=col>days_per_week</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;int&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>Pat-1216</td><td>Run </td><td>3</td></tr>\n",
"\t<tr><th scope=row>2</th><td>Pat-1550</td><td>Bike</td><td>2</td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-2299</td><td>Bike</td><td>5</td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-6787</td><td>Bike</td><td>4</td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-7973</td><td>Swim</td><td>2</td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-2729</td><td>Bike</td><td>7</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 3\n",
"\\begin{tabular}{r|lll}\n",
" & id\\_sport & sport\\_type & days\\_per\\_week\\\\\n",
" & <fct> & <fct> & <int>\\\\\n",
"\\hline\n",
"\t1 & Pat-1216 & Run & 3\\\\\n",
"\t2 & Pat-1550 & Bike & 2\\\\\n",
"\t3 & Pat-2299 & Bike & 5\\\\\n",
"\t4 & Pat-6787 & Bike & 4\\\\\n",
"\t5 & Pat-7973 & Swim & 2\\\\\n",
"\t6 & Pat-2729 & Bike & 7\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 3\n",
"\n",
"| <!--/--> | id_sport &lt;fct&gt; | sport_type &lt;fct&gt; | days_per_week &lt;int&gt; |\n",
"|---|---|---|---|\n",
"| 1 | Pat-1216 | Run | 3 |\n",
"| 2 | Pat-1550 | Bike | 2 |\n",
"| 3 | Pat-2299 | Bike | 5 |\n",
"| 4 | Pat-6787 | Bike | 4 |\n",
"| 5 | Pat-7973 | Swim | 2 |\n",
"| 6 | Pat-2729 | Bike | 7 |\n",
"\n"
],
"text/plain": [
" id_sport sport_type days_per_week\n",
"1 Pat-1216 Run 3 \n",
"2 Pat-1550 Bike 2 \n",
"3 Pat-2299 Bike 5 \n",
"4 Pat-6787 Bike 4 \n",
"5 Pat-7973 Swim 2 \n",
"6 Pat-2729 Bike 7 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# create sports questionnaire from for 200 patients\n",
"id_sport <- sample(id, size = 200, replace = FALSE)\n",
"sport_type <- sample(c(\"Run\", \"Swim\", \"Bike\"), size = 200, replace = TRUE)\n",
"days_per_week <- sample(1:7, size = 200, replace = TRUE)\n",
"\n",
"form_sport <- data.frame(id_sport, sport_type, days_per_week)\n",
"head(form_sport)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 2</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id_meds</th><th scope=col>med_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>Pat-5105</td><td>Lisinopril </td></tr>\n",
"\t<tr><th scope=row>2</th><td>Pat-5105</td><td>Lipitor </td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-5105</td><td>Azithromycin </td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-5105</td><td>Metformin </td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-8181</td><td>Lipitor </td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-8181</td><td>Levothyroxine</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 2\n",
"\\begin{tabular}{r|ll}\n",
" & id\\_meds & med\\_type\\\\\n",
" & <fct> & <fct>\\\\\n",
"\\hline\n",
"\t1 & Pat-5105 & Lisinopril \\\\\n",
"\t2 & Pat-5105 & Lipitor \\\\\n",
"\t3 & Pat-5105 & Azithromycin \\\\\n",
"\t4 & Pat-5105 & Metformin \\\\\n",
"\t5 & Pat-8181 & Lipitor \\\\\n",
"\t6 & Pat-8181 & Levothyroxine\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 2\n",
"\n",
"| <!--/--> | id_meds &lt;fct&gt; | med_type &lt;fct&gt; |\n",
"|---|---|---|\n",
"| 1 | Pat-5105 | Lisinopril |\n",
"| 2 | Pat-5105 | Lipitor |\n",
"| 3 | Pat-5105 | Azithromycin |\n",
"| 4 | Pat-5105 | Metformin |\n",
"| 5 | Pat-8181 | Lipitor |\n",
"| 6 | Pat-8181 | Levothyroxine |\n",
"\n"
],
"text/plain": [
" id_meds med_type \n",
"1 Pat-5105 Lisinopril \n",
"2 Pat-5105 Lipitor \n",
"3 Pat-5105 Azithromycin \n",
"4 Pat-5105 Metformin \n",
"5 Pat-8181 Lipitor \n",
"6 Pat-8181 Levothyroxine"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# create medication and morbidity form for 20 patients with one line per medication/morbidity\n",
"# meds\n",
"id_meds <- sample(id, size = 20, replace = FALSE)\n",
"med_types <- c(\"Lisinopril\", \"Levothyroxine\", \"Azithromycin\",\n",
" \"Metformin\", \"Lipitor\", \"Hydrochlorothiazide\")\n",
"form_meds <- as.data.frame(matrix(nrow = 0, ncol = 2))\n",
"for(i in 1:20) {\n",
" n <- sample(1:6, 1)\n",
" curr_id <- rep(id_meds[i], n)\n",
" med_sample <- sample(med_types, size = n, replace = FALSE)\n",
" form_meds <- rbind(form_meds, data.frame(curr_id, med_sample))\n",
"}\n",
"names(form_meds) <- c(\"id_meds\", \"med_type\")\n",
"head(form_meds)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 2</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id_morb</th><th scope=col>morb_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>Pat-5105</td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>2</th><td>Pat-8181</td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-8181</td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-4919</td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-7693</td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-7693</td><td>Parkinsons</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 2\n",
"\\begin{tabular}{r|ll}\n",
" & id\\_morb & morb\\_type\\\\\n",
" & <fct> & <fct>\\\\\n",
"\\hline\n",
"\t1 & Pat-5105 & Cancer \\\\\n",
"\t2 & Pat-8181 & COPD \\\\\n",
"\t3 & Pat-8181 & Parkinsons\\\\\n",
"\t4 & Pat-4919 & Parkinsons\\\\\n",
"\t5 & Pat-7693 & COPD \\\\\n",
"\t6 & Pat-7693 & Parkinsons\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 2\n",
"\n",
"| <!--/--> | id_morb &lt;fct&gt; | morb_type &lt;fct&gt; |\n",
"|---|---|---|\n",
"| 1 | Pat-5105 | Cancer |\n",
"| 2 | Pat-8181 | COPD |\n",
"| 3 | Pat-8181 | Parkinsons |\n",
"| 4 | Pat-4919 | Parkinsons |\n",
"| 5 | Pat-7693 | COPD |\n",
"| 6 | Pat-7693 | Parkinsons |\n",
"\n"
],
"text/plain": [
" id_morb morb_type \n",
"1 Pat-5105 Cancer \n",
"2 Pat-8181 COPD \n",
"3 Pat-8181 Parkinsons\n",
"4 Pat-4919 Parkinsons\n",
"5 Pat-7693 COPD \n",
"6 Pat-7693 Parkinsons"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# morbidity\n",
"morb_types <- c(\"Cancer\", \"HIV\", \"COPD\", \"Parkinsons\")\n",
"form_morb <- as.data.frame(matrix(nrow = 0, ncol = 2))\n",
"for(i in 1:20) {\n",
" n <- sample(1:4, 1)\n",
" curr_id <- rep(id_meds[i], n)\n",
" morb_sample <- sample(morb_types, size = n, replace = FALSE)\n",
" form_morb <- rbind(form_morb, data.frame(curr_id, morb_sample))\n",
"}\n",
"names(form_morb) <- c(\"id_morb\", \"morb_type\")\n",
"head(form_morb)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"TRUE"
],
"text/latex": [
"TRUE"
],
"text/markdown": [
"TRUE"
],
"text/plain": [
"[1] TRUE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"TRUE"
],
"text/latex": [
"TRUE"
],
"text/markdown": [
"TRUE"
],
"text/plain": [
"[1] TRUE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"FALSE"
],
"text/latex": [
"FALSE"
],
"text/markdown": [
"FALSE"
],
"text/plain": [
"[1] FALSE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"FALSE"
],
"text/latex": [
"FALSE"
],
"text/markdown": [
"FALSE"
],
"text/plain": [
"[1] FALSE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"TRUE"
],
"text/latex": [
"TRUE"
],
"text/markdown": [
"TRUE"
],
"text/plain": [
"[1] TRUE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"FALSE"
],
"text/latex": [
"FALSE"
],
"text/markdown": [
"FALSE"
],
"text/plain": [
"[1] FALSE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"FALSE"
],
"text/latex": [
"FALSE"
],
"text/markdown": [
"FALSE"
],
"text/plain": [
"[1] FALSE"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"24"
],
"text/latex": [
"24"
],
"text/markdown": [
"24"
],
"text/plain": [
"[1] 24"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"3"
],
"text/latex": [
"3"
],
"text/markdown": [
"3"
],
"text/plain": [
"[1] 3"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# check ids presence\n",
"all(form_psych$id_psych %in% form_bl$id)\n",
"all(form_sport$id_sport %in% form_bl$id)\n",
"all(form_psych$id_psych %in% form_sport$id_sport)\n",
"all(form_sport$id_sport %in% form_psych$id_psych)\n",
"all(form_meds$id_meds %in% form_bl$id)\n",
"all(form_meds$id_meds %in% form_sport$id_sport)\n",
"all(form_meds$id_meds %in% form_psych$id_psych)\n",
"# how many ids in sport and psych match?\n",
"length(which(form_sport$id_sport %in% form_psych$id_psych))\n",
"# how many ids in sport and meds match?\n",
"length(which(form_sport$id_sport %in% unique(form_meds$id_meds)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# This is where we start to perform merging/joining."
]
},
{
"cell_type": "code",
"execution_count": 10,
"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>200</li><li>7</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 200\n",
"\\item 7\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 200\n",
"2. 7\n",
"\n",
"\n"
],
"text/plain": [
"[1] 200 7"
]
},
"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>1000</li><li>7</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 1000\n",
"\\item 7\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 1000\n",
"2. 7\n",
"\n",
"\n"
],
"text/plain": [
"[1] 1000 7"
]
},
"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>24</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 24\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 24\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 24 6"
]
},
"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>100</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 100\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 100\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 100 6"
]
},
"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>200</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 200\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 200\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 200 6"
]
},
"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>276</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 276\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 276\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 276 6"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# merging procedures baseR\n",
"bl_sport <- merge(form_bl, form_sport,\n",
" by.x = \"id\", by.y = \"id_sport\")\n",
"bl_sport_all_x <- merge(form_bl, form_sport,\n",
" by.x = \"id\", by.y = \"id_sport\",\n",
" all.x = TRUE)\n",
"psych_sport <- merge(form_psych, form_sport,\n",
" by.x = \"id_psych\", by.y = \"id_sport\")\n",
"psych_sport_all_x <- merge(form_psych, form_sport,\n",
" by.x = \"id_psych\", by.y = \"id_sport\",\n",
" all.x = TRUE)\n",
"psych_sport_all_y <- merge(form_psych, form_sport,\n",
" by.x = \"id_psych\", by.y = \"id_sport\",\n",
" all.y = TRUE)\n",
"psych_sport_all_x_and_y <- merge(form_psych, form_sport,\n",
" by.x = \"id_psych\", by.y = \"id_sport\",\n",
" all.x = TRUE, all.y = TRUE)\n",
"\n",
"dim(bl_sport)\n",
"dim(bl_sport_all_x)\n",
"dim(psych_sport)\n",
"dim(psych_sport_all_x)\n",
"dim(psych_sport_all_y)\n",
"dim(psych_sport_all_x_and_y)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning message:\n",
"“Column `id`/`id_sport` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id`/`id_sport` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id_psych`/`id_sport` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id_psych`/`id_sport` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id_psych`/`id_sport` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id_psych`/`id_sport` joining factors with different levels, coercing to character vector”"
]
},
{
"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>200</li><li>7</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 200\n",
"\\item 7\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 200\n",
"2. 7\n",
"\n",
"\n"
],
"text/plain": [
"[1] 200 7"
]
},
"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>1000</li><li>7</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 1000\n",
"\\item 7\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 1000\n",
"2. 7\n",
"\n",
"\n"
],
"text/plain": [
"[1] 1000 7"
]
},
"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>24</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 24\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 24\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 24 6"
]
},
"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>100</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 100\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 100\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 100 6"
]
},
"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>200</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 200\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 200\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 200 6"
]
},
"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>276</li><li>6</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 276\n",
"\\item 6\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 276\n",
"2. 6\n",
"\n",
"\n"
],
"text/plain": [
"[1] 276 6"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# merging with dplyr joins\n",
"bl_sport_inner <- inner_join(form_bl, form_sport, by = c(\"id\" = \"id_sport\"))\n",
"bl_sport_left <- left_join(form_bl, form_sport, by = c(\"id\" = \"id_sport\"))\n",
"psych_sport_inner <- inner_join(form_psych, form_sport, by = c(\"id_psych\" = \"id_sport\"))\n",
"psych_sport_left <- left_join(form_psych, form_sport, by = c(\"id_psych\" = \"id_sport\"))\n",
"psych_sport_right <- right_join(form_psych, form_sport, by = c(\"id_psych\" = \"id_sport\"))\n",
"psych_sport_full <- full_join(form_psych, form_sport, by = c(\"id_psych\" = \"id_sport\"))\n",
"\n",
"dim(bl_sport_inner)\n",
"dim(bl_sport_left)\n",
"dim(psych_sport_inner)\n",
"dim(psych_sport_left)\n",
"dim(psych_sport_right)\n",
"dim(psych_sport_full)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning message:\n",
"“Column `id`/`id_meds` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id`/`id_meds` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id`/`id_meds` joining factors with different levels, coercing to character vector”Warning message:\n",
"“Column `id`/`id_meds` joining factors with different levels, coercing to character vector”"
]
},
{
"data": {
"text/html": [
"66"
],
"text/latex": [
"66"
],
"text/markdown": [
"66"
],
"text/plain": [
"[1] 66"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"1046"
],
"text/latex": [
"1046"
],
"text/markdown": [
"1046"
],
"text/plain": [
"[1] 1046"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"66"
],
"text/latex": [
"66"
],
"text/markdown": [
"66"
],
"text/plain": [
"[1] 66"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"1046"
],
"text/latex": [
"1046"
],
"text/markdown": [
"1046"
],
"text/plain": [
"[1] 1046"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# merging with unique and repeated ids\n",
"# baseR\n",
"bl_meds <- merge(x = form_bl, y = form_meds, by.x = \"id\", by.y = \"id_meds\")\n",
"# dplyr\n",
"bl_meds_inner <- inner_join(x = form_bl, y = form_meds, by = c(\"id\" = \"id_meds\"))\n",
"bl_meds_left <- left_join(x = form_bl, y = form_meds, by = c(\"id\" = \"id_meds\"))\n",
"bl_meds_right <- right_join(x = form_bl, y = form_meds, by = c(\"id\" = \"id_meds\"))\n",
"bl_meds_full <- full_join(x = form_bl, y = form_meds, by = c(\"id\" = \"id_meds\"))\n",
"\n",
"nrow(bl_meds_inner)\n",
"nrow(bl_meds_left)\n",
"nrow(bl_meds_right)\n",
"nrow(bl_meds_full)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 10 × 6</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id</th><th scope=col>gender</th><th scope=col>age</th><th scope=col>weight</th><th scope=col>height</th><th scope=col>med_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>Pat-7578</td><td>male </td><td>98</td><td>65</td><td>187</td><td>Metformin </td></tr>\n",
"\t<tr><th scope=row>2</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine </td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lipitor </td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Metformin </td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Hydrochlorothiazide</td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lisinopril </td></tr>\n",
"\t<tr><th scope=row>7</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Azithromycin </td></tr>\n",
"\t<tr><th scope=row>8</th><td>Pat-4964</td><td>male </td><td>66</td><td>73</td><td>196</td><td>Levothyroxine </td></tr>\n",
"\t<tr><th scope=row>9</th><td>Pat-4964</td><td>male </td><td>66</td><td>73</td><td>196</td><td>Metformin </td></tr>\n",
"\t<tr><th scope=row>10</th><td>Pat-4964</td><td>male </td><td>66</td><td>73</td><td>196</td><td>Lipitor </td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 10 × 6\n",
"\\begin{tabular}{r|llllll}\n",
" & id & gender & age & weight & height & med\\_type\\\\\n",
" & <chr> & <fct> & <int> & <int> & <int> & <fct>\\\\\n",
"\\hline\n",
"\t1 & Pat-7578 & male & 98 & 65 & 187 & Metformin \\\\\n",
"\t2 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine \\\\\n",
"\t3 & Pat-5350 & female & 20 & 89 & 190 & Lipitor \\\\\n",
"\t4 & Pat-5350 & female & 20 & 89 & 190 & Metformin \\\\\n",
"\t5 & Pat-5350 & female & 20 & 89 & 190 & Hydrochlorothiazide\\\\\n",
"\t6 & Pat-5350 & female & 20 & 89 & 190 & Lisinopril \\\\\n",
"\t7 & Pat-5350 & female & 20 & 89 & 190 & Azithromycin \\\\\n",
"\t8 & Pat-4964 & male & 66 & 73 & 196 & Levothyroxine \\\\\n",
"\t9 & Pat-4964 & male & 66 & 73 & 196 & Metformin \\\\\n",
"\t10 & Pat-4964 & male & 66 & 73 & 196 & Lipitor \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 10 × 6\n",
"\n",
"| <!--/--> | id &lt;chr&gt; | gender &lt;fct&gt; | age &lt;int&gt; | weight &lt;int&gt; | height &lt;int&gt; | med_type &lt;fct&gt; |\n",
"|---|---|---|---|---|---|---|\n",
"| 1 | Pat-7578 | male | 98 | 65 | 187 | Metformin |\n",
"| 2 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine |\n",
"| 3 | Pat-5350 | female | 20 | 89 | 190 | Lipitor |\n",
"| 4 | Pat-5350 | female | 20 | 89 | 190 | Metformin |\n",
"| 5 | Pat-5350 | female | 20 | 89 | 190 | Hydrochlorothiazide |\n",
"| 6 | Pat-5350 | female | 20 | 89 | 190 | Lisinopril |\n",
"| 7 | Pat-5350 | female | 20 | 89 | 190 | Azithromycin |\n",
"| 8 | Pat-4964 | male | 66 | 73 | 196 | Levothyroxine |\n",
"| 9 | Pat-4964 | male | 66 | 73 | 196 | Metformin |\n",
"| 10 | Pat-4964 | male | 66 | 73 | 196 | Lipitor |\n",
"\n"
],
"text/plain": [
" id gender age weight height med_type \n",
"1 Pat-7578 male 98 65 187 Metformin \n",
"2 Pat-5350 female 20 89 190 Levothyroxine \n",
"3 Pat-5350 female 20 89 190 Lipitor \n",
"4 Pat-5350 female 20 89 190 Metformin \n",
"5 Pat-5350 female 20 89 190 Hydrochlorothiazide\n",
"6 Pat-5350 female 20 89 190 Lisinopril \n",
"7 Pat-5350 female 20 89 190 Azithromycin \n",
"8 Pat-4964 male 66 73 196 Levothyroxine \n",
"9 Pat-4964 male 66 73 196 Metformin \n",
"10 Pat-4964 male 66 73 196 Lipitor "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"head(bl_meds_inner, n = 10)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Warning message:\n",
"“Column `id`/`id_morb` joining character vector and factor, coercing into character vector”"
]
},
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 7</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id</th><th scope=col>gender</th><th scope=col>age</th><th scope=col>weight</th><th scope=col>height</th><th scope=col>med_type</th><th scope=col>morb_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>1</th><td>Pat-7578</td><td>male </td><td>98</td><td>65</td><td>187</td><td>Metformin </td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>2</th><td>Pat-7578</td><td>male </td><td>98</td><td>65</td><td>187</td><td>Metformin </td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine</td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine</td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine</td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine</td><td>Parkinsons</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 7\n",
"\\begin{tabular}{r|lllllll}\n",
" & id & gender & age & weight & height & med\\_type & morb\\_type\\\\\n",
" & <chr> & <fct> & <int> & <int> & <int> & <fct> & <fct>\\\\\n",
"\\hline\n",
"\t1 & Pat-7578 & male & 98 & 65 & 187 & Metformin & Parkinsons\\\\\n",
"\t2 & Pat-7578 & male & 98 & 65 & 187 & Metformin & COPD \\\\\n",
"\t3 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & COPD \\\\\n",
"\t4 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & HIV \\\\\n",
"\t5 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & Cancer \\\\\n",
"\t6 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & Parkinsons\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 7\n",
"\n",
"| <!--/--> | id &lt;chr&gt; | gender &lt;fct&gt; | age &lt;int&gt; | weight &lt;int&gt; | height &lt;int&gt; | med_type &lt;fct&gt; | morb_type &lt;fct&gt; |\n",
"|---|---|---|---|---|---|---|---|\n",
"| 1 | Pat-7578 | male | 98 | 65 | 187 | Metformin | Parkinsons |\n",
"| 2 | Pat-7578 | male | 98 | 65 | 187 | Metformin | COPD |\n",
"| 3 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | COPD |\n",
"| 4 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | HIV |\n",
"| 5 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | Cancer |\n",
"| 6 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | Parkinsons |\n",
"\n"
],
"text/plain": [
" id gender age weight height med_type morb_type \n",
"1 Pat-7578 male 98 65 187 Metformin Parkinsons\n",
"2 Pat-7578 male 98 65 187 Metformin COPD \n",
"3 Pat-5350 female 20 89 190 Levothyroxine COPD \n",
"4 Pat-5350 female 20 89 190 Levothyroxine HIV \n",
"5 Pat-5350 female 20 89 190 Levothyroxine Cancer \n",
"6 Pat-5350 female 20 89 190 Levothyroxine Parkinsons"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# merging repeated and repeated ids\n",
"bl_meds_morb_left <- left_join(bl_meds_inner, form_morb, by = c(\"id\" = \"id_morb\"))\n",
"head(bl_meds_morb_left)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below you can see how data is duplicated if you start joining with repeated IDs. Specifically, \"Pat-5350\" starts with one line in the baseline data.frame. When joined with the medication data, the baseline data is repeated six times. Then, when further joining this to the morbidity data, every line is again repeated for each morbidity. At this stage it is clear, that the data.frame no longer is a useful representation of the original data."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 1 × 5</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id</th><th scope=col>gender</th><th scope=col>age</th><th scope=col>weight</th><th scope=col>height</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>144</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 1 × 5\n",
"\\begin{tabular}{r|lllll}\n",
" & id & gender & age & weight & height\\\\\n",
" & <fct> & <fct> & <int> & <int> & <int>\\\\\n",
"\\hline\n",
"\t144 & Pat-5350 & female & 20 & 89 & 190\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 1 × 5\n",
"\n",
"| <!--/--> | id &lt;fct&gt; | gender &lt;fct&gt; | age &lt;int&gt; | weight &lt;int&gt; | height &lt;int&gt; |\n",
"|---|---|---|---|---|---|\n",
"| 144 | Pat-5350 | female | 20 | 89 | 190 |\n",
"\n"
],
"text/plain": [
" id gender age weight height\n",
"144 Pat-5350 female 20 89 190 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"form_bl[form_bl$id == \"Pat-5350\", ]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 2</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id_meds</th><th scope=col>med_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>49</th><td>Pat-5350</td><td>Levothyroxine </td></tr>\n",
"\t<tr><th scope=row>50</th><td>Pat-5350</td><td>Lipitor </td></tr>\n",
"\t<tr><th scope=row>51</th><td>Pat-5350</td><td>Metformin </td></tr>\n",
"\t<tr><th scope=row>52</th><td>Pat-5350</td><td>Hydrochlorothiazide</td></tr>\n",
"\t<tr><th scope=row>53</th><td>Pat-5350</td><td>Lisinopril </td></tr>\n",
"\t<tr><th scope=row>54</th><td>Pat-5350</td><td>Azithromycin </td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 2\n",
"\\begin{tabular}{r|ll}\n",
" & id\\_meds & med\\_type\\\\\n",
" & <fct> & <fct>\\\\\n",
"\\hline\n",
"\t49 & Pat-5350 & Levothyroxine \\\\\n",
"\t50 & Pat-5350 & Lipitor \\\\\n",
"\t51 & Pat-5350 & Metformin \\\\\n",
"\t52 & Pat-5350 & Hydrochlorothiazide\\\\\n",
"\t53 & Pat-5350 & Lisinopril \\\\\n",
"\t54 & Pat-5350 & Azithromycin \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 2\n",
"\n",
"| <!--/--> | id_meds &lt;fct&gt; | med_type &lt;fct&gt; |\n",
"|---|---|---|\n",
"| 49 | Pat-5350 | Levothyroxine |\n",
"| 50 | Pat-5350 | Lipitor |\n",
"| 51 | Pat-5350 | Metformin |\n",
"| 52 | Pat-5350 | Hydrochlorothiazide |\n",
"| 53 | Pat-5350 | Lisinopril |\n",
"| 54 | Pat-5350 | Azithromycin |\n",
"\n"
],
"text/plain": [
" id_meds med_type \n",
"49 Pat-5350 Levothyroxine \n",
"50 Pat-5350 Lipitor \n",
"51 Pat-5350 Metformin \n",
"52 Pat-5350 Hydrochlorothiazide\n",
"53 Pat-5350 Lisinopril \n",
"54 Pat-5350 Azithromycin "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"form_meds[form_meds$id_meds == \"Pat-5350\", ]"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 4 × 2</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id_morb</th><th scope=col>morb_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>40</th><td>Pat-5350</td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>41</th><td>Pat-5350</td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>42</th><td>Pat-5350</td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>43</th><td>Pat-5350</td><td>Parkinsons</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 4 × 2\n",
"\\begin{tabular}{r|ll}\n",
" & id\\_morb & morb\\_type\\\\\n",
" & <fct> & <fct>\\\\\n",
"\\hline\n",
"\t40 & Pat-5350 & COPD \\\\\n",
"\t41 & Pat-5350 & HIV \\\\\n",
"\t42 & Pat-5350 & Cancer \\\\\n",
"\t43 & Pat-5350 & Parkinsons\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 4 × 2\n",
"\n",
"| <!--/--> | id_morb &lt;fct&gt; | morb_type &lt;fct&gt; |\n",
"|---|---|---|\n",
"| 40 | Pat-5350 | COPD |\n",
"| 41 | Pat-5350 | HIV |\n",
"| 42 | Pat-5350 | Cancer |\n",
"| 43 | Pat-5350 | Parkinsons |\n",
"\n"
],
"text/plain": [
" id_morb morb_type \n",
"40 Pat-5350 COPD \n",
"41 Pat-5350 HIV \n",
"42 Pat-5350 Cancer \n",
"43 Pat-5350 Parkinsons"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"form_morb[form_morb$id_morb == \"Pat-5350\", ]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 6 × 6</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id</th><th scope=col>gender</th><th scope=col>age</th><th scope=col>weight</th><th scope=col>height</th><th scope=col>med_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>2</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine </td></tr>\n",
"\t<tr><th scope=row>3</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lipitor </td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Metformin </td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Hydrochlorothiazide</td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lisinopril </td></tr>\n",
"\t<tr><th scope=row>7</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Azithromycin </td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 6 × 6\n",
"\\begin{tabular}{r|llllll}\n",
" & id & gender & age & weight & height & med\\_type\\\\\n",
" & <chr> & <fct> & <int> & <int> & <int> & <fct>\\\\\n",
"\\hline\n",
"\t2 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine \\\\\n",
"\t3 & Pat-5350 & female & 20 & 89 & 190 & Lipitor \\\\\n",
"\t4 & Pat-5350 & female & 20 & 89 & 190 & Metformin \\\\\n",
"\t5 & Pat-5350 & female & 20 & 89 & 190 & Hydrochlorothiazide\\\\\n",
"\t6 & Pat-5350 & female & 20 & 89 & 190 & Lisinopril \\\\\n",
"\t7 & Pat-5350 & female & 20 & 89 & 190 & Azithromycin \\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 6 × 6\n",
"\n",
"| <!--/--> | id &lt;chr&gt; | gender &lt;fct&gt; | age &lt;int&gt; | weight &lt;int&gt; | height &lt;int&gt; | med_type &lt;fct&gt; |\n",
"|---|---|---|---|---|---|---|\n",
"| 2 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine |\n",
"| 3 | Pat-5350 | female | 20 | 89 | 190 | Lipitor |\n",
"| 4 | Pat-5350 | female | 20 | 89 | 190 | Metformin |\n",
"| 5 | Pat-5350 | female | 20 | 89 | 190 | Hydrochlorothiazide |\n",
"| 6 | Pat-5350 | female | 20 | 89 | 190 | Lisinopril |\n",
"| 7 | Pat-5350 | female | 20 | 89 | 190 | Azithromycin |\n",
"\n"
],
"text/plain": [
" id gender age weight height med_type \n",
"2 Pat-5350 female 20 89 190 Levothyroxine \n",
"3 Pat-5350 female 20 89 190 Lipitor \n",
"4 Pat-5350 female 20 89 190 Metformin \n",
"5 Pat-5350 female 20 89 190 Hydrochlorothiazide\n",
"6 Pat-5350 female 20 89 190 Lisinopril \n",
"7 Pat-5350 female 20 89 190 Azithromycin "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"bl_meds_inner[bl_meds_inner$id == \"Pat-5350\", ]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<caption>A data.frame: 24 × 7</caption>\n",
"<thead>\n",
"\t<tr><th></th><th scope=col>id</th><th scope=col>gender</th><th scope=col>age</th><th scope=col>weight</th><th scope=col>height</th><th scope=col>med_type</th><th scope=col>morb_type</th></tr>\n",
"\t<tr><th></th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
"</thead>\n",
"<tbody>\n",
"\t<tr><th scope=row>3</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine </td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>4</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine </td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>5</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine </td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>6</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Levothyroxine </td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>7</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lipitor </td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>8</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lipitor </td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>9</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lipitor </td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>10</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lipitor </td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>11</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Metformin </td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>12</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Metformin </td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>13</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Metformin </td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>14</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Metformin </td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>15</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Hydrochlorothiazide</td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>16</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Hydrochlorothiazide</td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>17</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Hydrochlorothiazide</td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>18</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Hydrochlorothiazide</td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>19</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lisinopril </td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>20</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lisinopril </td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>21</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lisinopril </td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>22</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Lisinopril </td><td>Parkinsons</td></tr>\n",
"\t<tr><th scope=row>23</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Azithromycin </td><td>COPD </td></tr>\n",
"\t<tr><th scope=row>24</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Azithromycin </td><td>HIV </td></tr>\n",
"\t<tr><th scope=row>25</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Azithromycin </td><td>Cancer </td></tr>\n",
"\t<tr><th scope=row>26</th><td>Pat-5350</td><td>female</td><td>20</td><td>89</td><td>190</td><td>Azithromycin </td><td>Parkinsons</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"A data.frame: 24 × 7\n",
"\\begin{tabular}{r|lllllll}\n",
" & id & gender & age & weight & height & med\\_type & morb\\_type\\\\\n",
" & <chr> & <fct> & <int> & <int> & <int> & <fct> & <fct>\\\\\n",
"\\hline\n",
"\t3 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & COPD \\\\\n",
"\t4 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & HIV \\\\\n",
"\t5 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & Cancer \\\\\n",
"\t6 & Pat-5350 & female & 20 & 89 & 190 & Levothyroxine & Parkinsons\\\\\n",
"\t7 & Pat-5350 & female & 20 & 89 & 190 & Lipitor & COPD \\\\\n",
"\t8 & Pat-5350 & female & 20 & 89 & 190 & Lipitor & HIV \\\\\n",
"\t9 & Pat-5350 & female & 20 & 89 & 190 & Lipitor & Cancer \\\\\n",
"\t10 & Pat-5350 & female & 20 & 89 & 190 & Lipitor & Parkinsons\\\\\n",
"\t11 & Pat-5350 & female & 20 & 89 & 190 & Metformin & COPD \\\\\n",
"\t12 & Pat-5350 & female & 20 & 89 & 190 & Metformin & HIV \\\\\n",
"\t13 & Pat-5350 & female & 20 & 89 & 190 & Metformin & Cancer \\\\\n",
"\t14 & Pat-5350 & female & 20 & 89 & 190 & Metformin & Parkinsons\\\\\n",
"\t15 & Pat-5350 & female & 20 & 89 & 190 & Hydrochlorothiazide & COPD \\\\\n",
"\t16 & Pat-5350 & female & 20 & 89 & 190 & Hydrochlorothiazide & HIV \\\\\n",
"\t17 & Pat-5350 & female & 20 & 89 & 190 & Hydrochlorothiazide & Cancer \\\\\n",
"\t18 & Pat-5350 & female & 20 & 89 & 190 & Hydrochlorothiazide & Parkinsons\\\\\n",
"\t19 & Pat-5350 & female & 20 & 89 & 190 & Lisinopril & COPD \\\\\n",
"\t20 & Pat-5350 & female & 20 & 89 & 190 & Lisinopril & HIV \\\\\n",
"\t21 & Pat-5350 & female & 20 & 89 & 190 & Lisinopril & Cancer \\\\\n",
"\t22 & Pat-5350 & female & 20 & 89 & 190 & Lisinopril & Parkinsons\\\\\n",
"\t23 & Pat-5350 & female & 20 & 89 & 190 & Azithromycin & COPD \\\\\n",
"\t24 & Pat-5350 & female & 20 & 89 & 190 & Azithromycin & HIV \\\\\n",
"\t25 & Pat-5350 & female & 20 & 89 & 190 & Azithromycin & Cancer \\\\\n",
"\t26 & Pat-5350 & female & 20 & 89 & 190 & Azithromycin & Parkinsons\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"A data.frame: 24 × 7\n",
"\n",
"| <!--/--> | id &lt;chr&gt; | gender &lt;fct&gt; | age &lt;int&gt; | weight &lt;int&gt; | height &lt;int&gt; | med_type &lt;fct&gt; | morb_type &lt;fct&gt; |\n",
"|---|---|---|---|---|---|---|---|\n",
"| 3 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | COPD |\n",
"| 4 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | HIV |\n",
"| 5 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | Cancer |\n",
"| 6 | Pat-5350 | female | 20 | 89 | 190 | Levothyroxine | Parkinsons |\n",
"| 7 | Pat-5350 | female | 20 | 89 | 190 | Lipitor | COPD |\n",
"| 8 | Pat-5350 | female | 20 | 89 | 190 | Lipitor | HIV |\n",
"| 9 | Pat-5350 | female | 20 | 89 | 190 | Lipitor | Cancer |\n",
"| 10 | Pat-5350 | female | 20 | 89 | 190 | Lipitor | Parkinsons |\n",
"| 11 | Pat-5350 | female | 20 | 89 | 190 | Metformin | COPD |\n",
"| 12 | Pat-5350 | female | 20 | 89 | 190 | Metformin | HIV |\n",
"| 13 | Pat-5350 | female | 20 | 89 | 190 | Metformin | Cancer |\n",
"| 14 | Pat-5350 | female | 20 | 89 | 190 | Metformin | Parkinsons |\n",
"| 15 | Pat-5350 | female | 20 | 89 | 190 | Hydrochlorothiazide | COPD |\n",
"| 16 | Pat-5350 | female | 20 | 89 | 190 | Hydrochlorothiazide | HIV |\n",
"| 17 | Pat-5350 | female | 20 | 89 | 190 | Hydrochlorothiazide | Cancer |\n",
"| 18 | Pat-5350 | female | 20 | 89 | 190 | Hydrochlorothiazide | Parkinsons |\n",
"| 19 | Pat-5350 | female | 20 | 89 | 190 | Lisinopril | COPD |\n",
"| 20 | Pat-5350 | female | 20 | 89 | 190 | Lisinopril | HIV |\n",
"| 21 | Pat-5350 | female | 20 | 89 | 190 | Lisinopril | Cancer |\n",
"| 22 | Pat-5350 | female | 20 | 89 | 190 | Lisinopril | Parkinsons |\n",
"| 23 | Pat-5350 | female | 20 | 89 | 190 | Azithromycin | COPD |\n",
"| 24 | Pat-5350 | female | 20 | 89 | 190 | Azithromycin | HIV |\n",
"| 25 | Pat-5350 | female | 20 | 89 | 190 | Azithromycin | Cancer |\n",
"| 26 | Pat-5350 | female | 20 | 89 | 190 | Azithromycin | Parkinsons |\n",
"\n"
],
"text/plain": [
" id gender age weight height med_type morb_type \n",
"3 Pat-5350 female 20 89 190 Levothyroxine COPD \n",
"4 Pat-5350 female 20 89 190 Levothyroxine HIV \n",
"5 Pat-5350 female 20 89 190 Levothyroxine Cancer \n",
"6 Pat-5350 female 20 89 190 Levothyroxine Parkinsons\n",
"7 Pat-5350 female 20 89 190 Lipitor COPD \n",
"8 Pat-5350 female 20 89 190 Lipitor HIV \n",
"9 Pat-5350 female 20 89 190 Lipitor Cancer \n",
"10 Pat-5350 female 20 89 190 Lipitor Parkinsons\n",
"11 Pat-5350 female 20 89 190 Metformin COPD \n",
"12 Pat-5350 female 20 89 190 Metformin HIV \n",
"13 Pat-5350 female 20 89 190 Metformin Cancer \n",
"14 Pat-5350 female 20 89 190 Metformin Parkinsons\n",
"15 Pat-5350 female 20 89 190 Hydrochlorothiazide COPD \n",
"16 Pat-5350 female 20 89 190 Hydrochlorothiazide HIV \n",
"17 Pat-5350 female 20 89 190 Hydrochlorothiazide Cancer \n",
"18 Pat-5350 female 20 89 190 Hydrochlorothiazide Parkinsons\n",
"19 Pat-5350 female 20 89 190 Lisinopril COPD \n",
"20 Pat-5350 female 20 89 190 Lisinopril HIV \n",
"21 Pat-5350 female 20 89 190 Lisinopril Cancer \n",
"22 Pat-5350 female 20 89 190 Lisinopril Parkinsons\n",
"23 Pat-5350 female 20 89 190 Azithromycin COPD \n",
"24 Pat-5350 female 20 89 190 Azithromycin HIV \n",
"25 Pat-5350 female 20 89 190 Azithromycin Cancer \n",
"26 Pat-5350 female 20 89 190 Azithromycin Parkinsons"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"bl_meds_morb_left[bl_meds_morb_left$id == \"Pat-5350\", ]"
]
},
{
"cell_type": "code",
"execution_count": 20,
"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>'Mersenne-Twister'</li><li>'Inversion'</li></ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 'Mersenne-Twister'\n",
"\\item 'Inversion'\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 'Mersenne-Twister'\n",
"2. 'Inversion'\n",
"\n",
"\n"
],
"text/plain": [
"[1] \"Mersenne-Twister\" \"Inversion\" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"RNGkind()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"R version 3.5.1 (2018-07-02)\n",
"Platform: x86_64-conda_cos6-linux-gnu (64-bit)\n",
"Running under: Debian GNU/Linux 10 (buster)\n",
"\n",
"Matrix products: default\n",
"BLAS/LAPACK: /home/jupyterlab/conda/envs/r/lib/R/lib/libRlapack.so\n",
"\n",
"locale:\n",
" [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 \n",
" [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 \n",
" [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C \n",
"[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C \n",
"\n",
"attached base packages:\n",
"[1] stats graphics grDevices utils datasets methods base \n",
"\n",
"other attached packages:\n",
"[1] dplyr_0.8.5\n",
"\n",
"loaded via a namespace (and not attached):\n",
" [1] Rcpp_1.0.4.6 assertthat_0.2.1 digest_0.6.25 crayon_1.3.4 \n",
" [5] IRdisplay_0.7.0 repr_1.1.0 R6_2.4.1 lifecycle_0.2.0 \n",
" [9] jsonlite_1.6.1 magrittr_1.5 evaluate_0.14 pillar_1.4.3 \n",
"[13] rlang_0.4.5 uuid_0.1-4 vctrs_0.2.4 ellipsis_0.3.0 \n",
"[17] IRkernel_0.8.12 tools_3.5.1 glue_1.4.0 purrr_0.3.4 \n",
"[21] compiler_3.5.1 pkgconfig_2.0.3 base64enc_0.1-3 htmltools_0.4.0 \n",
"[25] pbdZMQ_0.3-3 tidyselect_1.0.0 tibble_3.0.1 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sessionInfo()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "conda-env-r-r"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment