--- title: "Introduction to R Studio" output: pdf_document: default html_document: default --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ##R Markdown This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . I will be using R Markdown to develop R demos in class, and will share R Markdown code so that you can become familiar with it as well. ##RStudio There are a couple versions of R available, though I find students prefer RStudio because of its attractive IDE (Interactive Development Environment). After installing the appropriate version of R from its website (), then optionally installing RStudio (), you can open R to begin; we will assume you have installed R Studio. When you first open R Studio, your screen will typically be divided into 4 frames. ![R Studio layout](/STAT 515/R_Studio_Opening_Screen.png) The upper left-hand frame is used for code development, the lower left-hand frame is the console--as though R commands were being entered manually, the upper right-hand frame includes information about active R variables and data objects, while the lower right-hand screen includes plots, help and R packages. ##A first R session In this first R session, we will assume that we have saved tab-delimited data from the first lecture in the file Examp9p4.txt and placed it in our STAT 515 folder. To simplify reading the data set into R, select Session, then Set Working Directory->Choose Directory, browse to STAT 515 and select Open. R will now assume this is the location to read input files and place output files. The commands below read the tab-delimited table, store it in a data frame, which is R's main data object, print the data frame (Example_1), and then print summary information about the variables in the data frame. ```{r} Example_1=read.table("Examp9p4.txt",header=T) Example_1 summary(Example_1) ``` Note the changes in the other frames; the environment frame now contains information about Example_1, and the console includes the commands and command output. The next set of commands can print histograms side by side; they require loading an R package, lattice, to do so; lattice has a simpler syntax for side-by-side histograms that R's default hist() command lacks; look for the graph in the lower right-hand frame under the Plots tab. If you want to repeat a command (or re-execute it after a slight edit), go to the console and hit the "up" arrow on your keypad, and R will retrieve the command. Now hit the return key and the command will be executed again. ```{r global_options, warning=FALSE} library(lattice) histogram(~ Value | Group, data=Example_1) ``` Side-by-side boxplots do not require the lattice package (though since lattice has been loaded, its data sets and functions are available for the remainder of this R session). Note that the boxplot command supports an equation syntax that is not available in the default hist() command. ```{r} boxplot(Value~Group, data=Example_1) ```