


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A step-by-step guide on creating and managing R projects, scripts, and data in RStudio. It covers creating an R project, organizing scripts, housekeeping, commenting, and importing data. It also discusses saving and exporting data, preparing data for R, and handling broken data.
What you will learn
Typology: Study notes
1 / 42
This page cannot be seen from the preview
Don't miss anything!
Material prepared in part by Etienne Low-Decarie, Zofia Taranu, Patrick Thompson Vaughn DiMarco
ย๏ Create an R project ย๏ Look at Data in R ย๏ Create data that is appropriate for use with R ย๏ Import data ย๏ Save and export data
Create an R project ย๏ A folder in R-Studio for all your work on one project (eg. Thesis chapter) ย๏ Helps you stay organized ย๏ R will load from and save to here
Create an R project in RStudio ย๏ In R Studio, select create project from the project menu (top right corner)
Create an R script
R Projects can have multiple scripts ย๏ Open the file: Data and Projects in R-Studio.R ย๏ this script has all of the code from this workshop ย๏ Recommendation ย๏ type code into the blank script that you created ย๏ refer to provided code only if needed ย๏ avoid copy pasting or running the code directly from our script
Why use R Projects?" ย๏ Close and reopen your R Project ย๏ In the R โ Projects menu ย๏ Both our script and the one you created will open automatically ย๏ Great way to organize your various projects
ย๏ Remove all variables from memory ย๏ Prevents errors such as use of older data ย๏ Demo โ add some test data to your workspace and then see how rm(list=ls()) removes it A<-โTestโ
rm(list = ls() ) Type this in your R sc ript
ย๏ # symbol tells R to ignore this ย๏ commenting/documenting ย๏ annotate someoneโs script is good way to learn ย๏ remember what you did ย๏ tell collaborators what you did ย๏ good step towards reproducible science
ย๏ Tells R where your scripts and data are ย๏ type โgetwd()โ in the console to see your working directory ย๏ RStudio automatically sets the directory to the folder containing your R project ย๏ a โ/โ separates folders and file ย๏ You can also set your working directory in the โsessionโ menu
ย๏ You can have sub directories within your working directory to organize your data, plots, ectโฆ ย๏ โ./โ โ will tell R to start from the current working directory ย๏ Eg. We have a folder called โDataโ in our working directory ย๏ โ./Dataโ โ will tell R that you want to access files in that folder
Notice that R-Studio now provides information on the CO2 data
look at the whole dataframe look at the first few rows names of the columns in the dataframe structure of the dataframe attributes of the dataframe number of columns number of rows summary statistics plot of all variable combinations CO head(CO2) names(CO2) str(CO2) attributes(CO2) ncol(CO2) nrow(CO2) summary(CO2) plot(CO2)