What is R?
According to their site The R - Project for Statistical Computing:
'R is a language and environment for statistical computing and graphics.'
'R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, ...) and graphical techniques, and is highly extensible.'
'One of R's strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed.'
Source code of older versions of R is available here. Contributed extension packages; Questions About R. If you have questions about R like how to download and install the software, or what the license terms are, please read our answers to frequently asked questions before you send an email. Dec 17, 2020 The software is similar to H&R Block Deluxe 2020 but it also works for both the federal program and one state program, too, so it’s useful if you need a little more coverage.
- The software is similar to H&R Block Deluxe 2020 but it also works for both the federal program and one state program, too, so it’s useful if you need a little more coverage.
- A very useful feature of the R environment is the possibility to expand existing functions and to easily write custom functions. In fact, most of the R software can be viewed as a series of R functions. Syntax to define functions.
Obtaining a copy of the R applications
R is free software - see the R site above for the terms of use. It runs on a wide variety of platforms including UNIX, Windows and MacOS.
Download a copy of the most recent version of this application from their site: The R - Project for Statistical Computing
The website will require you to choose a 'CRAN Mirror'. The idea is to find the location geographically closest to you.
Launching R Programs
In R you can enter each line of code at the prompt in a step-by-step approach. You may also save R programs as simple text files to open in a separate window so that you can enter multiple lines of code at once and save your commands.
Here is an example data set you may save on your computer:
Here is an example program:
The # symbol indicates a programmer's comment. This text is not read by the R application. This program can either be copied and pasted into the R command line, line by line or as an entire program. You may also source this program from where it is saved on your computer as shown below.
It is often useful to set a working directory so that file names without a pathname will refer to files in that directory on your system. The command getwd()
will print your working directory to your screen. The command setwd('/pathname')
sets the R working directory.
- On a Mac, your pathname is shown at the bottom of your Finder window,
(/Users/Username/Documents/... for example)
. - In Windows, the pathname is
C:/Users/Username/Documents/...
.
One nice feature of the step-by-step command lines in R is that you may scroll through previous commands using the Up and Down arrow keys. Here are a couple of other handy commands that you can use in R:
Here are the data files and programs to practice the above commands:
example1.dat, example2.txt, intro.R, intro_file.R
Data
Depending on the course, datasets are either presented within the context of the lesson or within a datasets folder. Common file extensions for data files include .dat, .csv, and .txt. You must download the data from your course website. Canvas provides instructions on how to save a file for Windows users or Mac users. A Save dialog box will be displayed and allow you to save the data file to the location you choose on your computer.
There are a number of ways to read data into your R session. Two popular commands used in the examples presented here are read.table
and scan
.
Install a Development Environment
The development environment is the application that you will use to open, edit, and execute R programs. If you already have a favorite development environment, you can see if it’s compatible with R (many of them are). If you don’t, we recommend one called RStudio.
Installing RStudio
- You need to have R installed first (see above)
- Download RStudio from the RStudio Website.
- Select the installer link that corresponds to your operating system (e.g. Windows, Mac OSX).
Help
If you need help understanding a command or its syntax type either ?command
, or help(command)
and R will display the help available on this topic. For instance, here is the help page for read.table from the command ?read.table
:
Note: Certain functions in R may NOT run on all platfroms (e.g., Windows, MAC, Linux, etc..) the same way. For example, you may get an error with the sink() function on your PC depending how the read/write permissions are set up. It should not be a problem using it on Linux or a MAC, or if you run your R programs in a Terminal. In the Windows version of R, you can delete or comment-out the sink() function, and save your output by clicking on File/Save to file. You can also explore other options/functions such as file() , capture.output() , etc... You can also copy and paste your output from the R console window into a seperate file.
Helpful Resources
The Department of Statistics offers two 1 credit online courses, STAT 484: Topics in R: Statistical Language and STAT 485 - Intermediate Topics in R Statistical Language. This would be a good step towards building a solid foundation in using R. In addition, you may also find the following references handy:
- The R Project Homepage.
- DataCamp offers a free Introduction to R course and many additional courses with a subscription.
- LinkedIn Learning at PSU includescourses on R.
- R Seek helps you find the R function you require.
- R Tutorial - web site at Clarkson University Department of Mathematics.
- Swirl: Learn R, in R.
To Install R
- Open an internet browser and go to www.r-project.org.
- Click the 'download R' link in the middle of the page under 'Getting Started.'
- Select a CRAN location (a mirror site) and click the corresponding link.
- Click on the 'Download R for (Mac) OS X' link at the top of the page.
- Click on the file containing the latest version of R under 'Files.'
- Save the .pkg file, double-click it to open, and follow the installation instructions.
- Now that R is installed, you need to download and install RStudio.
R Software Download For Windows
To Install RStudio
- Go to www.rstudio.com and click on the 'Download RStudio' button.
- Click on 'Download RStudio Desktop.'
- Click on the version recommended for your system, or the latest Mac version, save the .dmg file on your computer, double-click it to open, and then drag and drop it to your applications folder.
To Install the SDSFoundations Package
- Download SDSFoundations to your desktop (make sure it has the '.tgz' extension).
- Open RStudio.
- Click on the Packages tab in the bottom right window.
- Click 'Install.'
- Select install from 'Package Archive File.'
- Select the SDSFoundations package file from your desktop.
- Click install. You are done! You can now delete the SDSpackage file from your desktop.
R Software
To Install R:
- Open an internet browser and go to www.r-project.org.
- Click the 'download R' link in the middle of the page under 'Getting Started.'
- Select a CRAN location (a mirror site) and click the corresponding link.
- Click on the 'Download R for Windows' link at the top of the page.
- Click on the 'install R for the first time' link at the top of the page.
- Click 'Download R for Windows' and save the executable file somewhere on your computer. Run the .exe file and follow the installation instructions.
- Now that R is installed, you need to download and install RStudio.
To Install RStudio
- Go to www.rstudio.com and click on the 'Download RStudio' button.
- Click on 'Download RStudio Desktop.'
- Click on the version recommended for your system, or the latest Windows version, and save the executable file. Run the .exe file and follow the installation instructions.
To Install the SDSFoundations Package
R Software Pdf
- Download SDSFoundationsto your desktop (make sure it has the '.zip' extension).
- Open RStudio.
- Click on the Packages tab in the bottom right window.
- Click 'Install.'
- Select install from 'Package Archive File.'
- Select the SDSFoundations package file from your desktop.
- Click install. You are done! You can now delete the SDSpackage file from your desktop.