Information on R

Note on assignment

I tend to use x = 2 for assignment.
Most R users use x <- 2.
See this link: For a discussion

Note that you can call python from R:
R studio notes on package reticulate

R

Basic R links are:
Generic R: R.
Available via myASU, but it is more convenient to install on your own computer.

Rstudio, console for R, R studio (now Posit)

To install R under Windows:
   Google "install R under Windows"
   click on "Download R-x.x.x for Windows"
   Click on "Run"

Some of you may also want to use rstudio which gives you more
of a gui (visual point-and-click) interface to R.
rstudio also has a lot of nice tools built into.
But, for the basic R we will do, we won't need those tools.
You may like rstudio just because it combines the editor with the command line
and makes it easier to do a few things like saving graphs.

If I google "how do I download rstudio in windows I get":
To Install RStudio:
   1. Go to www.rstudio.com and click on the "Download RStudio" button.
   2. Click on "Download RStudio Desktop."
   3. 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.

This looks like a great R intro from Norman Matloff (who is very good): Matloff R Intro

Note that the lab at the end of Chapter 2 of ISLR (An Introduction to Statistical Learning) has a nice short R introduction.

Swirl: Easy way to learn R This look like it might be a super easy way to learn R: swirl stats .
   A few simple notes on swirl
Data Camp Free Intro to R

Note that if you go to http://swirlstats.com/students.html it tell you how
to get started installing R, rstudio, and swirl.

The official R documentation page is R documentation
and the official R intro is Introduction to R.
The writing in the R introduction can get very technical, but if you just read the initial parts of a section it is usually very good,
definitely worth a try.

This is a very simple introduction to R that Rob wrote for MBA's at Chicago:
Rob's Simple R Introduction

Short Reference Card

Google Tutorial

Google Tutorial

Princeton's R Introduction

Nice R books:
The Art of R Programming, Norman Matloff.

Learning R: A Step-by-Step Function Guide to Data Analysis 1st Edition by Richard Cotton.

Advanced R, Second Edition (Chapman & Hall/CRC The R Series) by Hadley Wickham | Jun 1, 2019

R for Data Science: Import, Tidy, Transform, Visualize, and Model Data 1st Edition by Hadley Wickham , Garrett Grolemund
R for Data Science
R for data science uses the "tidyverse": tidyverse
I tend to just use base R but a lot of people like the tidyverse tools and the graphics package ggplot does look nice.


A handy book for R graphics is R Graphics Cookbook, 2nd edition

R Markdown

In data science ``dynamic documents'' in which code and math and the output form code are combined have become very popular.

Rmarkdown (particularly in rstudio) has become very popular.

This seems like a nice tutorial from R bloggers: Getting Started with R Markdown - Guide and Cheatsheet

Here is the rstudio webpage for Rmarkdown rstudio on Rmarkdown

The rstudio cheatsheets are very useful, you can get them from the rstudio help, but here they are:
rmarkdown cheatsheet (from the rstudio help)    rmarkdown-reference.pdf

See also Part V of ``R for Data Science'' by Wickham and Grolemund.

Here is a simple ``Hello world, stats in R'' document with the corresponding Rmarkdown.
  Hello world regression in R, Rmarkdown
  Hello world regression in R, rendered html
  Hello world regression in R, short version, rendered html

Try going into rstudio, clicking to get a new Rmarkdown file and the clicking knit. Note that (if your Rmarkdown is simple) you can ``render'' the Rmarkdown to html or pdf (or word). If you play around with this file and consult the cheatsheets you get the hang of it but it takes a little while.

Mostly Rmarkdown is pretty easy, but some things can be tricky.
At the top of the fname.Rmd file there is a preamble that controls how the Rmarkdown is "rendered".
For example, you can render to pdf or html. It is not always easy to figure out how to get these
options to do what you want.

Rmarkdown has "code chunks" where you put in a chunk of R code.
There are then a lot of options on how the code and the output from the code are displayed.
In particular, you can cache (to disk) the results for a code chunk and specify which
previous chunks a chunk depends on. This way a chunk is only rerun when the code changes for the code for a chunk that it depends on changes.


Here is an example where of a section of notes written in Rmarkdown (note the preamble):
   markdown,    pdf

Here is an example where a tutorial was written in Rmarkdown
(note the cache=TRUE option is some of the code chunks and the dependson= is subsequent chunks):
   markdown,    pdf

R packages for Machine Learning
CRAN Task View: Machine Learning & Statistical Learning

OOS Loop in R

Here is a simple example of a loop in R to estimate the out-of-same root mean square error
for linear regression and the susedcars.csv data set using just x=(mileage,year) for y=price:
  do-cars-oos.R.

What is the oos loop trying to do?
  Out of sample Loss..

Intro Statistics Notes on R

A First Look at R

first R, pdf
first R, html
first R, Rmd
   first_R video

Data in R, Vectors, Lists, and Data Frames

R and Data, pdf
R and Data, html
R and Data, Rmd


Simple Data Analysis in R, plot and Simple Linear Regression

Simple data analysis, pdf
Simple data analysis, html
Simple data analysis, Rmd