<- c(1, 2, 3, 4, 5)
x x
[1] 1 2 3 4 5
For conducting analyses with data sets of hundreds to thousands of observations, calculating by hand is not feasible and you will need a statistical software. R is one of those. R can also be thought of as a high-level programming language. In fact, R is one of the top languages to be used by data analysts and data scientists. There are a lot of analysis packages in R that are currently developed and maintained by researchers around the world to deal with different data problems. Most importantly, R is free! In this section, we will learn how to use R to conduct basic statistical analyses.
RStudio is an integrated development environment (IDE) designed specifically for working with the R programming language. It provides a user-friendly interface that includes a source editor, console, environment pane, and tools for plotting, debugging, version control, and package management. RStudio supports both R and Python and is widely used for data analysis, statistical modeling, and reproducible research. It also integrates seamlessly with tools like R Markdown, Shiny, and Quarto, making it popular among data scientists, statisticians, and educators.
VS Code is a versatile code editor that supports multiple programming languages, including R. With the R extension for VS Code, users can write and execute R code, access R’s console, and utilize features like syntax highlighting, code completion, and debugging. While not as specialized as RStudio for R development, VS Code offers a lightweight alternative with extensive customization options and support for various programming tasks.
Positron IDE is the next-generation integrated development environment developed by Posit, the company behind RStudio. Designed to be a modern, extensible, and language-agnostic IDE, Positron builds on the strengths of RStudio while supporting a broader range of languages and workflows, including R, Python, and Quarto.
RStudio consists of several panes: - Source: Where you write scripts and markdown documents. - Console: Where you type and execute R commands. - Environment/History: Shows your variables and command history. - Files/Plots/Packages/Help/Viewer: For file management, viewing plots, managing packages, accessing help, and viewing web content.
R scripts are plain text files containing R code. You can create a new script in RStudio by clicking File > New File > R Script
.
Use ?function_name
or help(function_name)
to access help for any R function. For example:
Packages extend R’s functionality. Install a package with:
Load a package with:
R Markdown allows you to combine text, code, and output in a single document. Create a new R Markdown file in RStudio via File > New File > R Markdown...
.
Recently, the posit team has developed a new version of the R Markdown called quarto document, with the file extension .qmd
. It is still under rapid development.
Vectors are the most basic data structure in R.
You can perform operations on vectors:
Data frames are used for storing data tables. Create a data frame:
You can import data from files using read.csv()
or read.table()
.
This appendix is adapted from Why R?.