RStudio: Basics

You will need these steps to run R on your personal computer.

STEP 1. Visit http://www.r-project.org

STEP 2. Click on CRAN from the left menu

STEP 3. Select any CRAN mirror

STEP 4. Click on the Download R for your operating system

STEP 5. Click on the downloaded file and install it

 

 

 

 

 

You will need these steps to run RStudio on your personal computer.

STEP 1. Visit http://www.rstudio.com

STEP 2. Click on Download now button

STEP 3. Click on Download RStudio Desktop

STEP 4. Click on the file name under Recommended For Your System

STEP 5. Click on the downloaded file and install it

 

 

 

 

 

 

You will need these steps to run R on the UMM Server.

STEP 1. Visit http://umm-rstudio2.morris.umn.edu/

STEP 2. Sign in with your UMM Username and Password

 

 

 

 

 

 

 

 

 

There are two cases for getting the data: Existing data file on the course Moodle site , Creating a data file.

For existing data file on the course Moodle site, please follow these steps.

STEP 1. On the course Moodle site locate the data file and click on it to download to your computer. If it is a csv or txt file you are done.

STEP 2. If it is not a csv or txt file, say an Excel file, then open the file with Excel and save as a csv (or txt) file. (File -> Save As... Format: Comma Separated Values (.csv) or File -> Save As... Format: Tab Delimited Text (.txt))

For creating a data file, please follow these steps.

STEP 1. Run Excel. On the spread sheets type the variable name(s) on the column(s) of the first row.

STEP 2. Enter the data on the column(s)

STEP 3. Save the file as a csv or txt file. (File -> Save As... Format: Comma Separated Values (.csv) or File -> Save As... Format: Tab Delimited Text (.txt)

 

 

There are numerous ways to get data into R. Here, I will go over getting a .csv (.txt) into UMM RStudio server. If you have RStudio on your personal computer, skip straight to step 2.

STEP 1: Get your .csv(.txt) data file into RStudio

Run RStudio, in the Files tab, click Upload, and choose your csv (txt) file.

STEP 2. Load your data into RStudio

In RStudio, click on the Workspace tab, and then on "Import Dataset" -> "From text file". A file browser will open up, locate the .csv (.txt) file and click Open. You'll see a dialog that gives you a few options on the import. Of particular importance is making sure if you have column names in your file, that Header is set to "Yes". The column names should be bolded in the Data Frame box. Click "Import".

STEP 2 ALTERNATIVE. Load your data into RStudio

Type the following on the Console window. First one is for csv the secind one is for txt files.

filename <- read.csv(file.choose(),header=TRUE)

filename <- read.table(file.choose(),header=TRUE)

Basically, there are two types of outputs that you may want to move around: text and graphics. By doing so you my include the results of your analysis on your assignments and reports. In the following instructions, it is assumed that you would like to insert your analysis into a Word document.

STEP 1: Carry out your analysis in R. Depneding on your analysis it will produce either a text (that will appear on Console) or graphic (that will appear under the Plots tab).

For the text ouput

STEP 2 TEXT. Highlight the text output then from your browsers menu (not the RStudio menu) select Edit -> Copy

STEP 3 TEXT. Go to the Word document and paste, that is select Edit -> Paste

For the graphics ouput

STEP 2 GRAPHICS. Click on Export from Plots from Plots tab, and select Copy Plot to Clipboard...

STEP 3 GRAPHICS. Click on the graphics. From your browsers menu (not the RStudio menu) select Edit -> Select All, then select Edit -> Copy

STEP 4 GRAPHICS. Go to the Word document and paste, that is select Edit -> Paste

If it does not work replace Steps 3 and 4 with following.

STEP 3 (Alternative) GRAPHICS. Right click on the graphics. Select Save Image As ...

STEP 4 (Alternative) GRAPHICS. Open the saved image, Edit -> Select All. Copy and paste to the Word document.