Introduction to R and RStudio
- Use RStudio to write and run R programs.
- R has the usual arithmetic operators and mathematical functions.
- Use
<-to assign values to variables. - Use RStudio to create and manage projects with a consistent structure.
- Treat raw data as read-only.
- Treat generated output as disposable.
Data Structures and Subsetting Data
- Use
read.csvto read tabular data in R. - The basic data types in R are double, integer, complex, logical, and character.
- Data structures such as data frames are built on top of lists and vectors, with some added attributes.
- Indexing in R starts at 1, not 0.
- Access individual values by location using
[]. - Access slices of data using
[low:high]. - Access arbitrary sets of data using
[c(...)]. - Use logical operations and logical vectors to access subsets of data.
Exploring Data Frames
- Use
cbind()to add a new column to a data frame. - Use
rbind()to add a new row to a data frame. - Use
str(),summary(), nrow(),ncol(),dim(),colnames(),head(), andtypeof()` to understand the structure of a data frame. - Read in a csv file using
read.csv(). - Understand what
length()of a data frame represents.
R Packages and Seeking Help
- Use install.packages() to install packages (libraries) from CRAN
- Use
help()to get online help in R - Use ls() to list the variables in a program
- Use rm() to delete objects in a program
Manipulating Tibbles With Dplyr
- Use the
dplyrpackage to manipulate data frames. - Use
select()to choose variables from a data frame. - Use
filter()to choose data based on values. - Use
group_by()andsummarize()to work with subsets of data. - Use
mutate()to create new variables.
Creating Publication-Quality Graphics with ggplot2
- Use
ggplot2to create plots. - Think about graphics in layers: aesthetics, geometry, statistics, scale transformation, and grouping.
Wrap-up
- This course covered the essentials of R and RStudio for reproducible analysis, providing a strong foundation for further learning.
- Topics such as factors, matrices and
arrays, and more advanced concepts like data frame
manipulation with
tidyr, control flow, and functions are critical next steps. - Continued practice and exploration of R will benefit you, your team, and the wider research community.