Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
r_workshop2 [2019/09/16 17:24] fgabriel1891 |
r_workshop2 [2021/10/13 20:03] (current) lsherin |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <WRAP group> | ||
| + | <WRAP centeralign> | ||
| + | <WRAP important> | ||
| + | <wrap em> __MAJOR UPDATE__ </wrap> | ||
| + | |||
| + | <wrap em> As of Fall 2021, this wiki has been discontinued and is no longer being actively developed. </wrap> | ||
| + | |||
| + | <wrap em> All updated materials and announcements for the QCBS R Workshop Series are now housed on the [[https://r.qcbs.ca/workshops/r-workshop-02/|QCBS R Workshop website]]. Please update your bookmarks accordingly to avoid outdated material and/or broken links. </wrap> | ||
| + | |||
| + | <wrap em> Thank you for your understanding, </wrap> | ||
| + | |||
| + | <wrap em> Your QCBS R Workshop Coordinators. </wrap> | ||
| + | |||
| + | </WRAP> | ||
| + | </WRAP> | ||
| + | <WRAP clear></WRAP> | ||
| + | |||
| ======= QCBS R Workshops ======= | ======= QCBS R Workshops ======= | ||
| Line 9: | Line 26: | ||
| ====== Workshop 2: Loading and manipulating data ====== | ====== Workshop 2: Loading and manipulating data ====== | ||
| - | Developed by: Johanna Bradie, Vincent Fugère, Thomas Lamy, Gabriel Muñoz | + | Developed by: Johanna Bradie, Vincent Fugère, Thomas Lamy |
| **Summary:** In this workshop, you will learn how to load, view, and manipulate your data in R. You will learn basic commands to inspect and visualize your data, and learn how to fix errors that may have occurred while loading your data into R. In addition, you will learn how to write an R script, which is a text file that contains your R commands and allows you to rerun your analyses in one simple touch of a key (or maybe two, or three…)! We have included an advance users section where we will introduce tidyr and dplyr, two powerful tools to manage and re-format your dataset, as well as apply simple or complex functions on subsets of your data. This workshop will be useful for those progressing through the entire workshop series, but also for those who already have some experience in R and would like to become proficient with new tools and packages. | **Summary:** In this workshop, you will learn how to load, view, and manipulate your data in R. You will learn basic commands to inspect and visualize your data, and learn how to fix errors that may have occurred while loading your data into R. In addition, you will learn how to write an R script, which is a text file that contains your R commands and allows you to rerun your analyses in one simple touch of a key (or maybe two, or three…)! We have included an advance users section where we will introduce tidyr and dplyr, two powerful tools to manage and re-format your dataset, as well as apply simple or complex functions on subsets of your data. This workshop will be useful for those progressing through the entire workshop series, but also for those who already have some experience in R and would like to become proficient with new tools and packages. | ||
| Line 17: | Line 34: | ||
| Download the R script and data for this lesson: | Download the R script and data for this lesson: | ||
| - | - [[http://qcbs.ca/wiki/_media/script_workshop2.R|Script]] | + | - [[http://qcbs.ca/wiki/_media/script_workshop02-en.r|Script]] |
| - [[http://qcbs.ca/wiki/_media/co2_good.csv|Dataset 1]] | - [[http://qcbs.ca/wiki/_media/co2_good.csv|Dataset 1]] | ||
| - | - [[http://qcbs.ca/wiki/_media/co2_broken.csv|Dataset 2]] | + | - [[https://raw.githubusercontent.com/QCBSRworkshops/workshop02/dev/workshop02-en/data/co2_broken.csv|Dataset 2]] (//After following this link, right-click on the page to save the file as .csv//). |
| ===== Learning Objectives ===== | ===== Learning Objectives ===== | ||
| 1. Creating an R project | 1. Creating an R project | ||
| + | |||
| 2. Writing a script | 2. Writing a script | ||
| + | |||
| 3. Loading, exploring and saving data | 3. Loading, exploring and saving data | ||
| + | |||
| (For advanced users) | (For advanced users) | ||
| + | |||
| 4. Learn to manipulate data frames with tidyr, dplyr, maggritr | 4. Learn to manipulate data frames with tidyr, dplyr, maggritr | ||
| Line 48: | Line 69: | ||
| Place similar files inside of their own folders | Place similar files inside of their own folders | ||
| - | Keep version track | + | |
| + | Keep track of versions | ||
| {{:0_folderdata1.png?400|}} | {{:0_folderdata1.png?400|}} | ||
| Line 457: | Line 479: | ||
| **HINT: There are 4 problems!** | **HINT: There are 4 problems!** | ||
| - | Answers: | ||
| - | |||
| - | Answer #1 | ||
| - | <hidden> | ||
| Problem #1: The data appears to be lumped into one column | Problem #1: The data appears to be lumped into one column | ||
| Solution: | Solution: | ||
| - | <hidden> | + | |
| Re-import the data, but specify the separation among entries. | Re-import the data, but specify the separation among entries. | ||
| The sep argument tells R what character separates the values on each line of the file. | The sep argument tells R what character separates the values on each line of the file. | ||
| Line 472: | Line 490: | ||
| ?read.csv | ?read.csv | ||
| </code> | </code> | ||
| - | </hidden> | ||
| - | </hidden> | ||
| - | Answer #2 | + | |
| - | <hidden> | + | |
| Problem #2: The data does not start until the third line of the txt file, so you end up with notes on the file as the headings. | Problem #2: The data does not start until the third line of the txt file, so you end up with notes on the file as the headings. | ||
| <code rsplus | > | <code rsplus | > | ||
| Line 483: | Line 498: | ||
| Solution: | Solution: | ||
| - | <hidden> | + | |
| To fix this problem, you can tell R to skip the first two rows when reading in this file. | To fix this problem, you can tell R to skip the first two rows when reading in this file. | ||
| <code rsplus | > | <code rsplus | > | ||
| Line 489: | Line 504: | ||
| head(CO2) # You can now see that the CO2 object has the appropriate headings | head(CO2) # You can now see that the CO2 object has the appropriate headings | ||
| </code> | </code> | ||
| - | </hidden> | ||
| - | </hidden> | ||
| Answer #3 | Answer #3 | ||
| - | <hidden> | + | |
| Problem #3: "conc" and "uptake" variables are considered factors instead of numbers, because there are comments/text in the numeric columns. | Problem #3: "conc" and "uptake" variables are considered factors instead of numbers, because there are comments/text in the numeric columns. | ||
| <code rsplus | > | <code rsplus | > | ||
| Line 504: | Line 517: | ||
| Solution: | Solution: | ||
| - | <hidden> | + | |
| <code rsplus | > | <code rsplus | > | ||
| ?read.csv | ?read.csv | ||
| Line 523: | Line 536: | ||
| str(CO2) # You can see that conc variable is now an integer and the uptake variable is now treated as numeric | str(CO2) # You can see that conc variable is now an integer and the uptake variable is now treated as numeric | ||
| </code> | </code> | ||
| - | </hidden> | ||
| - | </hidden> | ||
| - | Answer #4 | + | |
| - | <hidden> | + | |
| Problem #4: There are only two treatments (chilled and nonchilled) but there are spelling errors causing it to look like 4 different treatments. | Problem #4: There are only two treatments (chilled and nonchilled) but there are spelling errors causing it to look like 4 different treatments. | ||
| <code rsplus | > | <code rsplus | > | ||
| Line 536: | Line 547: | ||
| Solution: | Solution: | ||
| - | <hidden> | ||
| <code rsplus | > | <code rsplus | > | ||
| # You can use which() to find rows with the typo "nnchilled" | # You can use which() to find rows with the typo "nnchilled" | ||
| Line 556: | Line 566: | ||
| str(CO2) # Fixed! | str(CO2) # Fixed! | ||
| </code> | </code> | ||
| - | </hidden> | + | --- |
| - | </hidden> | + | |
| - | + | ||
| - | ---- | + | |
