R is a data analysis system widely used to perform statistics in the life sciences research, social and behavior sciences, and countless other disciplines. Over the years, it has become a comprehensive programming environment. In fact, many of the web apps used to present data are using R as the backend software.
Let’s look at some basic things it can do!
R can perform a variety of numerical operations.
5-3
## [1] 2
R input arrays of data.
a = c(1,3,5,6,7,0)
a
## [1] 1 3 5 6 7 0
R can also do array vector algebra
a * a
## [1] 1 9 25 36 49 0
a * rev(a)
## [1] 0 21 30 30 21 0
R can also plot data. These plots, when executed in RStudio, end up in the Plots tab. Or, if executed in a Notebook will be embedded below.
plot(cars)
R is also made more powerful through the vast number of packages people in the R programming community have developed. Many of these can be found in the Packages tab. In this course, packages you need to use will be installed on the RStudio Server but you are welcome to install them on your R install on your personal computer as well.
R packages are loaded into your current R session using the libary() command. For example, we can load a more comprehensive plotting environment called ggplot to make better looking graphs.
library(ggplot2)
Programming a ggplot plot is a little more involved but yields often nicer looking results. Execute the command below and see what you get!
ggplot(cars, aes(x=speed, y=dist)) + geom_point()
In the code block below, copy in the ggplot commands in the previous code block. Then, add the command geom_smooth() to your existing command. Execute and see what you see!