This is an introduction to R designed for participants with no programming experience.
In this section, you will learn:
R and RStudio are separate downloads and installations. R is the underlying statistical computing environment, but using R alone is no fun. RStudio is a graphical integrated development environment (IDE) that makes using R much easier and more interactive.
R is a coding language and system for statistical computing and graphics. RStudio is a powerful, open-source software for data science and scientific research. It can be used for data analysis and visualization purposes.
If you already have R and RStudio installed:
sessionInfo()
, which will also display which version of R you are running. Go on the CRAN website and check whether a more recent version is available. If so, please download and install it. You can check here for more information on how to remove old versions from your system.If you don’t have R and RStudio installed:
.exe
file that was just downloaded.R is a coding language and system for statistical computing and graphics. RStudio is a powerful, open-source software for data science and
If you already have R and RStudio installed:
sessionInfo()
, which will also display which version of R you are running. Go on the CRAN website and check whether a more recent version is available. If so, please download and install it. In any case, make sure you have at least R 3.2.If you don’t have R and RStudio installed:
.pkg
file for the latest R version.R is a coding language and system for statistical computing and graphics. RStudio is a powerful, open-source software for data science and scientific research. It can be used for data analysis and visualization purposes.
sudo apt-get install r-base
, and for Fedora sudo yum install R
), but we don’t recommend this approach as the versions provided by this are usually out of date. In any case, make sure you have at least R 3.2.sudo dpkg -i rstudio-x.yy.zzz-amd64.deb
at the terminal).tidyverse
and RSQLite
packages. Start RStudio by double-clicking the icon and then type: install.packages(c("tidyverse", "RSQLite"))
. You can also do this by going to Tools -> Install Packages and typing the names of the packages you want to install, separated by a comma.Introduction to R
sqrt()
# calculate the square rootround()
# round a numberargs()
# find what arguments a function takeslength()
# how many elements are in a particular vectorclass()
# the class (the type of element) of an objectstr()
# an overview of the object and the elements it containstypeof
# determines the (R internal) type or storage mode of any objectc()
# create vector; add elements to vector%in%
# to test if a value is found in a vectoris.na()
# test if there are missing valuesna.omit()
# Returns the object with incomplete cases removedcomplete.cases()
# elements which are complete casesStarting with Data
download.file()
# download files from the internet to your computerread_csv()
# load CSV file into R memoryhead()
# shows the first 6 rowsview()
# invoke a spreadsheet-style data viewerread_delim()
# load a file in table format into R memorystr()
# check structure of the object and information about the class, length and content of each columndim()
# check dimension of data framenrow()
# returns the number of rowsncol()
# returns the number of columnstail()
# shows the last 6 rowsnames()
# returns the column names (synonym of colnames() for data frame objects)rownames()
# returns the row namessummary()
# summary statistics for each columnglimpse
# like str()
applied to a data frame but tries to show as much data as possiblefactor()
# create factorslevels()
# check levels of a factornlevels()
# check number of levels of a factoras.character()
# convert an object to a character vectoras.numeric()
# convert an object to a numeric vectoras.numeric(as.character(x))
# convert factors where the levels appear as characters to a numeric vectoras.numeric(levels(x))[x]
# convert factors where the levels appear as numbers to a numeric vectorplot()
# plot an objectaddNA()
# convert NA into a factor leveldata.frame()
# create a data.frame objectymd()
# convert a vector representing year, month, and day to a Date vectorpaste()
# concatenate vectors after converting to characterData Wrangling with dplyr and tidyr
str()
# check structure of the object and information about the class, length and content of each columnview()
# invoke a spreadsheet-style data viewerselect()
# select columns of a data framefilter()
# allows you to select a subset of rows in a data frame%>%
# pipes to select and filter at the same timemutate()
# create new columns based on the values in existing columnshead()
# shows the first 6 rowsgroup_by()
# split the data into groups, apply some analysis to each group, and then combine the results.summarize()
# collapses each group into a single-row summary of that groupmean()
# calculate the mean value of a vector!is.na()
# test if there are no missing valuesprint()
# print values to the consolemin()
# return the minimum value of a vectorarrange()
# arrange rows by variablesdesc()
# transform a vector into a format that will be sorted in descending ordercount()
# counts the total number of records for each categorypivot_wider()
# reshape a data frame by a key-value pair across multiple columnspivot_longer()
# reshape a data frame by collapsing into a key-value pairreplace_na()
# Replace NAs with specified valuesn_distinct()
# get a count of unique valueswrite_csv()
# save to a csv formatted fileData Visualization with ggplot2
read_csv()
# load a csv formatted file into R memoryggplot2(data= , aes(x= , y= )) + geom_point( ) + facet_wrap () + theme_bw() + theme()
# skeleton for creating plot layersaes()
# by selecting the variables to be plotted and the variables to define the presentation such as plotting size, shape color, etc.geom_
# graphical representation of the data in the plot (points, lines, bars). To add a geom to the plot use + operatorfacet_wrap()
# allows to split one plot into multiple plots based on a factor included in the datasetlabs()
# set labels to plottheme_bw()
# set the background to whitetheme()
# used to locally modify one or more theme elements in a specific ggplot object+
# arrange ggplots horizontally/
# arrange ggplots verticallyplot_layout()
# set width and height of individual plots in a patchwork of plotsggsave()
# save a ggplotProcessing JSON data
read_json()
# load json object to an R objectOff-campus? Please use the Software VPN and choose the group UCIFull to access licensed content. For more information, please Click here
Software VPN is not available for guests, so they may not have access to some content when connecting from off-campus.