Skip to content

Commit

Permalink
missing column added in 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gabymahrholz committed Oct 8, 2024
1 parent 3948446 commit d2f8043
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 240 deletions.
456 changes: 228 additions & 228 deletions .Rhistory

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .Rproj.user/EEE9B81B/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab": 6
"activeTab": 4
}
3 changes: 1 addition & 2 deletions .Rproj.user/EEE9B81B/rmd-outputs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
D:/OneDrive - University of Glasgow/Teaching_2/2024-25/Level 2 labs/2A_chapter1/chapter_0102.html
C:/Users/Lenovo/Downloads/test.html
D:/OneDrive - University of Glasgow/Teaching_2/2024-25/Level 2 labs/project/Rmd_test.html
D:/OneDrive - University of Glasgow/R_Book/analysis-v3-main/data/ch1_2.html
D:/OneDrive - University of Glasgow/Teaching_2/2024-25/Level 2/datasets/Alter teaching SPSS/data_ch4/Alter.html

Expand Down
1 change: 1 addition & 0 deletions .Rproj.user/EEE9B81B/sources/prop/INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FR_Book_L2%2Fanalysis-v3%2F_qua
D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FR_Book_L2%2Fanalysis-v3%2Findex.qmd="83BB1C5B"
D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FTeaching_2%2F2024-25%2FLevel%202%20labs%2F2A_chapter1%2Fchapter_0102.Rmd="8C2681BF"
D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FTeaching_2%2F2024-25%2FLevel%202%20labs%2F2A_chapter3%2F03_data_viz.Rmd="C157BD41"
D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FTeaching_2%2F2024-25%2FLevel%202%20labs%2Fproject%2FRmd_test.Rmd="F4EAD707"
D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FTeaching_2%2F2024-25%2FLevel%202%2Fdatasets%2FAlter%20teaching%20SPSS%2FVSSL%20CODE%20ANALYSIS%20OUTPUT.Rmd="933B0F5C"
D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FTeaching_2%2F2024-25%2FLevel%202%2Fdatasets%2FAlter%20teaching%20SPSS%2Fdata_ch4%2FAlter.Rmd="4C6D86E7"
D%3A%2FOneDrive%20-%20University%20of%20Glasgow%2FTeaching_2%2F2024-25%2FLevel%202%2Fdatasets%2FBBC_Loneliness%2Fchapter_1.Rmd="AB65009E"
Expand Down
1 change: 1 addition & 0 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ D:/OneDrive - University of Glasgow/R_Book_L2/analysis-v3/02-wrangling.qmd="239B
D:/OneDrive - University of Glasgow/R_Book_L2/analysis-v3/03-wrangling2.qmd="44869D8D"
D:/OneDrive - University of Glasgow/R_Book_L2/analysis-v3/04-dataviz.qmd="774ACD6C"
D:/OneDrive - University of Glasgow/R_Book_L2/analysis-v3/index.qmd="D9578480"
D:/OneDrive - University of Glasgow/Teaching_2/2024-25/Level 2 labs/project/Rmd_test.Rmd="CCDEBB5C"
4 changes: 2 additions & 2 deletions .quarto/_freeze/03-wrangling2/execute-results/html.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .quarto/cites/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"04-prob-binom-one-sample.qmd":[],"12-one-way-anova.qmd":[],"04-dataviz2.qmd":[],"11-multiple-regression.qmd":[],"07-independent.qmd":[],"05-independent.qmd":[],"06-chi-square-one-sample.qmd":[],"12-factorial-anova.qmd":[],"04-dataviz.qmd":[],"07-apes.qmd":[],"04-chi-square-one-sample.qmd":[],"webexercises.qmd":[],"references.qmd":[],"07-paired.qmd":[],"05-dataviz2.qmd":[],"11-one-way-anova.qmd":[],"instructions.qmd":["usethis"],"08-paired.qmd":[],"02-wrangling.qmd":[],"06-independent.qmd":[],"03-dataviz.qmd":[],"09-simple-regression.qmd":[],"01-basics.qmd":[],"appendix-b-updating-packages.qmd":[],"appendix-y-license.qmd":[],"13-factorial-anova.qmd":[],"10-multiple-regression.qmd":[],"09-correlation.qmd":[],"05-chi-square-one-sample.qmd":[],"08-correlation.qmd":[],"appendix-d-symbols.qmd":[],"10-regression.qmd":[],"appendix-a-installing-r.qmd":[],"appendix-c-exporting-server.qmd":[],"03-wrangling2.qmd":[],"appendix-x-How-to-cite-R.qmd":[],"06-paired.qmd":[],"index.qmd":[]}
{"webexercises.qmd":[],"appendix-a-installing-r.qmd":[],"appendix-c-exporting-server.qmd":[],"references.qmd":[],"04-dataviz.qmd":[],"10-regression.qmd":[],"05-dataviz2.qmd":[],"11-one-way-anova.qmd":[],"05-independent.qmd":[],"07-paired.qmd":[],"05-chi-square-one-sample.qmd":[],"02-wrangling.qmd":[],"appendix-b-updating-packages.qmd":[],"07-apes.qmd":[],"08-correlation.qmd":[],"appendix-y-license.qmd":[],"01-basics.qmd":[],"03-dataviz.qmd":[],"04-dataviz2.qmd":[],"12-one-way-anova.qmd":[],"index.qmd":[],"11-multiple-regression.qmd":[],"06-paired.qmd":[],"06-independent.qmd":[],"appendix-x-How-to-cite-R.qmd":[],"08-paired.qmd":[],"03-wrangling2.qmd":[],"09-simple-regression.qmd":[],"07-independent.qmd":[],"04-chi-square-one-sample.qmd":[],"10-multiple-regression.qmd":[],"06-chi-square-one-sample.qmd":[],"12-factorial-anova.qmd":[],"13-factorial-anova.qmd":[],"04-prob-binom-one-sample.qmd":[],"09-correlation.qmd":[],"instructions.qmd":["usethis"],"appendix-d-symbols.qmd":[]}
2 changes: 1 addition & 1 deletion .quarto/xref/5f34e12a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"entries":[{"key":"sec-wrangling2","order":{"section":[3,0,0,0,0,0,0],"number":1}}],"headings":["intended-learning-outcomes","individual-walkthrough","activity-1-setup","activity-2-load-in-the-libraries-and-read-in-the-data","activity-3-confidence-in-understanding-open-science-practices","the-main-goal-is-to-compute-the-mean-understanding-score-per-participant.","steps-1-and-2-select-and-pivot","step-3-recoding-the-values","activity-4-survey-of-attitudes-toward-statistics-sats-28","the-main-goal-is-to-compute-the-mean-sats-28-score-for-each-of-the-4-subscales-per-participant-for-time-point-1.","steps-1-and-2-select-and-pivot-1","step-3-separate-subscale-information","step-4-identifying-reverse-coded-items-and-then-correct-them","step-5","step-6","activity-5-error-mode-perceptions-of-supervisory-support","the-main-goal-is-to-compute-the-mean-score-for-perceived-supervisory-support-per-participant.","activity-6-join-everything-together-with-_join","activity-7-knit-and-export","pair-coding","task-1-open-the-r-project-for-the-lab","task-2-open-your-.rmd-file-from-last-week-or-create-a-new-.rmd-file","task-3-load-in-the-library-and-read-in-the-data","task-4-calculating-the-mean-for-loneliness_pre","test-your-knowledge-and-challenge-yourself","knowledge-check","question-1","question-2","question-3","question-4","challenge-yourself","sec-wrangling2"],"options":{"chapters":true,"chapter-id":"sec-wrangling2"}}
{"headings":["intended-learning-outcomes","individual-walkthrough","activity-1-setup","activity-2-load-in-the-libraries-and-read-in-the-data","activity-3-confidence-in-understanding-open-science-practices","the-main-goal-is-to-compute-the-mean-understanding-score-per-participant.","steps-1-and-2-select-and-pivot","step-3-recoding-the-values","activity-4-survey-of-attitudes-toward-statistics-sats-28","the-main-goal-is-to-compute-the-mean-sats-28-score-for-each-of-the-4-subscales-per-participant-for-time-point-1.","steps-1-and-2-select-and-pivot-1","step-3-separate-subscale-information","step-4-identifying-reverse-coded-items-and-then-correct-them","step-5","step-6","activity-5-error-mode-perceptions-of-supervisory-support","the-main-goal-is-to-compute-the-mean-score-for-perceived-supervisory-support-per-participant.","activity-6-join-everything-together-with-_join","activity-7-knit-and-export","pair-coding","task-1-open-the-r-project-for-the-lab","task-2-open-your-.rmd-file-from-last-week-or-create-a-new-.rmd-file","task-3-load-in-the-library-and-read-in-the-data","task-4-calculating-the-mean-for-loneliness_pre","test-your-knowledge-and-challenge-yourself","knowledge-check","question-1","question-2","question-3","question-4","challenge-yourself","sec-wrangling2"],"entries":[{"key":"sec-wrangling2","order":{"number":1,"section":[3,0,0,0,0,0,0]}}],"options":{"chapter-id":"sec-wrangling2","chapters":true}}
2 changes: 1 addition & 1 deletion 03-wrangling2.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ Note: Since I (Gaby) like my columns arranged in a meaningful way, I will use `s

```{r eval=FALSE}
data_prp_final <- data_prp %>%
select(Code:Plan_prereg, Other_OS_behav_2:Time2_Understanding_OS) %>%
select(Code:Plan_prereg, Pre_reg_group:Time2_Understanding_OS) %>%
full_join(qrp_t1) %>%
full_join(understanding_t1) %>%
full_join(sats_t1) %>%
Expand Down
4 changes: 2 additions & 2 deletions _freeze/03-wrangling2/execute-results/html.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/03-wrangling2.html
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ <h1 class="title"><span id="sec-wrangling2" class="quarto-section-identifier"><s
<p>Note: Since I (Gaby) like my columns arranged in a meaningful way, I will use <code>select()</code> at the end to order them better.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1"></a>data_prp_final <span class="ot">&lt;-</span> data_prp <span class="sc">%&gt;%</span> </span>
<span id="cb28-2"><a href="#cb28-2"></a> <span class="fu">select</span>(Code<span class="sc">:</span>Plan_prereg, Other_OS_behav_2<span class="sc">:</span>Time2_Understanding_OS) <span class="sc">%&gt;%</span> </span>
<span id="cb28-2"><a href="#cb28-2"></a> <span class="fu">select</span>(Code<span class="sc">:</span>Plan_prereg, Pre_reg_group<span class="sc">:</span>Time2_Understanding_OS) <span class="sc">%&gt;%</span> </span>
<span id="cb28-3"><a href="#cb28-3"></a> <span class="fu">full_join</span>(qrp_t1) <span class="sc">%&gt;%</span> </span>
<span id="cb28-4"><a href="#cb28-4"></a> <span class="fu">full_join</span>(understanding_t1) <span class="sc">%&gt;%</span> </span>
<span id="cb28-5"><a href="#cb28-5"></a> <span class="fu">full_join</span>(sats_t1) <span class="sc">%&gt;%</span> </span>
Expand Down
2 changes: 1 addition & 1 deletion docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
"href": "03-wrangling2.html#activity-6-join-everything-together-with-_join",
"title": "3  Data wrangling II",
"section": "\n3.6 Activity 6: Join everything together with ???_join()\n",
"text": "3.6 Activity 6: Join everything together with ???_join()\n\nTime to join all the relevant data files into a single dataframe, which will be used in the next chapters on data visualization. There are four ways to join data: inner_join(), left_join(), right_join(), and full_join(). Each function behaves differently in terms of what information is retained from the two data objects. Here is a quick overview:\n\n\n\n\n\n\nInfo on mutating joins\n\n\n\nYou have 4 types of join functions you could make use of. Click on the panels to know more\n\n\ninner_join()\nleft_join()\nright_join()\nfull_join()\n\n\n\ninner_join() returns only the rows where the values in the column specified in the by = statement match in both tables.\n\n\ninner_join(): gif by Garrick Aden-Buie\n\n\n\nleft_join() retains the complete first (left) table and adds values from the second (right) table that have matching values in the column specified in the by = statement. Rows in the left table with no match in the right table will have missing values (NA) in the new columns.\n\n\nleft_join(): gif by Garrick Aden-Buie\n\n\n\nright_join() retains the complete second (right) table and adds values from the first (left) table that have matching values in the column specified in the by = statement. Rows in the right table with no match in the left table will have missing values (NA) in the new columns.\n\n\nright_join(): gif by Garrick Aden-Buie\n\n\n\nfull_join() returns all rows and all columns from both tables. NA values fill unmatched rows.\n\n\nfull_join(): gif by Garrick Aden-Buie\n\n\n\n\n\n\nFrom our original data_prp, we need to select demographics data and all summarised questionnaire data from time point 2. Next, we will join this with all other aggregated datasets from time point 1 which are currently stored in separate data objects in the Global Environment.\nWhile you may be familiar with inner_join() from last year, for this task, we want to retain all data from all the data objects. Therefore, we will use full_join(). Keep in mind, you can only join two data objects at a time, so the upcoming code chunk will involve a fair bit of piping and joining.\nNote: Since I (Gaby) like my columns arranged in a meaningful way, I will use select() at the end to order them better.\n\ndata_prp_final &lt;- data_prp %&gt;% \n select(Code:Plan_prereg, Other_OS_behav_2:Time2_Understanding_OS) %&gt;% \n full_join(qrp_t1) %&gt;% \n full_join(understanding_t1) %&gt;% \n full_join(sats_t1) %&gt;% \n full_join(super) %&gt;% \n select(Code:Plan_prereg, Pre_reg_group, SATS28_Affect_Time1_mean, SATS28_CognitiveCompetence_Time1_mean, SATS28_Value_Time1_mean, SATS28_Difficulty_Time1_mean, QRPs_Acceptance_Time1_mean, Time1_Understanding_OS, Other_OS_behav_2:Time2_Understanding_OS, Mean_Supervisor_Support)\n\n\n\n\n\n\n\nNo by argument in the code above?\n\n\n\nNote how I didn’t include a by argument in the code above. If you leave by = out, R will join the 2 data objects by ALL columns that have the same name.\nSpecial case 1: matching column names but different values\nIf you want more control, you should include the by argument; for example, if both data objects include a column age but data was recorded at 2 different time points. In that case, the information from both age columns should be retained and the by argument would not include age.\nSpecial case 2: different column names but matching values\nAnother special case presents when both data objects contain identical information but the variable names don’t match. Let’s say, both data objects contain gender information, but in one data object the variable is named gender and in the other one gender_label. In that case, your by argument needs to be modified as: by = join_by(gender == gender_label).\nMore info on joins can be found https://www.tidyverse.org/blog/2023/01/dplyr-1-1-0-joins/\n\n\nAnd this is basically the dataset we need for Chapter 4 and ?sec-dataviz2."
"text": "3.6 Activity 6: Join everything together with ???_join()\n\nTime to join all the relevant data files into a single dataframe, which will be used in the next chapters on data visualization. There are four ways to join data: inner_join(), left_join(), right_join(), and full_join(). Each function behaves differently in terms of what information is retained from the two data objects. Here is a quick overview:\n\n\n\n\n\n\nInfo on mutating joins\n\n\n\nYou have 4 types of join functions you could make use of. Click on the panels to know more\n\n\ninner_join()\nleft_join()\nright_join()\nfull_join()\n\n\n\ninner_join() returns only the rows where the values in the column specified in the by = statement match in both tables.\n\n\ninner_join(): gif by Garrick Aden-Buie\n\n\n\nleft_join() retains the complete first (left) table and adds values from the second (right) table that have matching values in the column specified in the by = statement. Rows in the left table with no match in the right table will have missing values (NA) in the new columns.\n\n\nleft_join(): gif by Garrick Aden-Buie\n\n\n\nright_join() retains the complete second (right) table and adds values from the first (left) table that have matching values in the column specified in the by = statement. Rows in the right table with no match in the left table will have missing values (NA) in the new columns.\n\n\nright_join(): gif by Garrick Aden-Buie\n\n\n\nfull_join() returns all rows and all columns from both tables. NA values fill unmatched rows.\n\n\nfull_join(): gif by Garrick Aden-Buie\n\n\n\n\n\n\nFrom our original data_prp, we need to select demographics data and all summarised questionnaire data from time point 2. Next, we will join this with all other aggregated datasets from time point 1 which are currently stored in separate data objects in the Global Environment.\nWhile you may be familiar with inner_join() from last year, for this task, we want to retain all data from all the data objects. Therefore, we will use full_join(). Keep in mind, you can only join two data objects at a time, so the upcoming code chunk will involve a fair bit of piping and joining.\nNote: Since I (Gaby) like my columns arranged in a meaningful way, I will use select() at the end to order them better.\n\ndata_prp_final &lt;- data_prp %&gt;% \n select(Code:Plan_prereg, Pre_reg_group:Time2_Understanding_OS) %&gt;% \n full_join(qrp_t1) %&gt;% \n full_join(understanding_t1) %&gt;% \n full_join(sats_t1) %&gt;% \n full_join(super) %&gt;% \n select(Code:Plan_prereg, Pre_reg_group, SATS28_Affect_Time1_mean, SATS28_CognitiveCompetence_Time1_mean, SATS28_Value_Time1_mean, SATS28_Difficulty_Time1_mean, QRPs_Acceptance_Time1_mean, Time1_Understanding_OS, Other_OS_behav_2:Time2_Understanding_OS, Mean_Supervisor_Support)\n\n\n\n\n\n\n\nNo by argument in the code above?\n\n\n\nNote how I didn’t include a by argument in the code above. If you leave by = out, R will join the 2 data objects by ALL columns that have the same name.\nSpecial case 1: matching column names but different values\nIf you want more control, you should include the by argument; for example, if both data objects include a column age but data was recorded at 2 different time points. In that case, the information from both age columns should be retained and the by argument would not include age.\nSpecial case 2: different column names but matching values\nAnother special case presents when both data objects contain identical information but the variable names don’t match. Let’s say, both data objects contain gender information, but in one data object the variable is named gender and in the other one gender_label. In that case, your by argument needs to be modified as: by = join_by(gender == gender_label).\nMore info on joins can be found https://www.tidyverse.org/blog/2023/01/dplyr-1-1-0-joins/\n\n\nAnd this is basically the dataset we need for Chapter 4 and ?sec-dataviz2."
},
{
"objectID": "03-wrangling2.html#activity-7-knit-and-export",
Expand Down

0 comments on commit d2f8043

Please sign in to comment.