R install
Windows
https://cran.r-project.org/bin/windows/base/
Mac
https://cran.r-project.org/bin/macosx/
Linux
https://cran.r-project.org/bin/linux/
Rstudio install
https://www.rstudio.com/products/rstudio/download/#download
These BOTH need to be installed.
In MacOS or Linux terminal type
R
bash
In windows cmd.exe type
R.exe
bash
Opening R this way opens the REPL…
REPL = read eval print loop
down history = ctrl-n or down
up history = ctrl-p or up
tab-completion
clear view = ctrl-l
quit = ctrl-d
newline = ctrl-c
help("data.frame") # help on data.frame
help("ls")
# up and down or j and k to scroll
# q to quit
# gives code for function
ls
builtins()
page(builtins)
grep("ls",builtins(),value=TRUE)
# save variables
ls()
save("myvars")
rm(list=ls())
ls()
load("myvars")
ls()
#save history
history()
q() # quit
history()
loadhistory()
savehistory(file="myhistory")
q()
loadhistory(file="myhistory")
history()
Syntax highlighting (Don't do during tutorial)
install.packages("devtools")
::install_github("jalvesaq/colorout")
devtoolslibrary("colorout")
4 pannels
Find the following tabs
Very useful:
Help selection menu (not panel) -> cheat sheets
MATLAB - private inter-workings, super user-friendly interface
R - viewable inter-workings, user-friendly interface, more features
For me, "Dataframe Oriented"
Feels between matlab and R
Generally Slowest (besides Octave)
<- 3
A <- 3
A.B remove(A) # unbind/delete
print(A.B) # query contents of A.B
4 -> A
print(A)
<- b <- c <- d <- 2 # chain assignment
a print(d)
print(a)
= 3
A = 3
A.B rm(A)
print(A.B)
print(A)
sample(1:4, 10, replace=TRUE)
<- for variables
= for arguments
= used to not work for variable assignment
# Anything after a hash sign is a comment - it will not be evaluated
8+5 # + is an operator
8*5 # Multiplication
5+3)/2 # Order of operations apply!
(<- 2^2
a ^2 a
b3=-4
a> abs(a) # Is b greater than abs(a)?
b < abs(a) # Is b less than abs (a)?
b # Is b equal to 3? Notice to equal signs instead of 1.
!= 3 # Is b not equal to 3?
b <= 4 # Is b less than or equal to 4?
b >= 4 # Is b greater than or equal to 4?
b TRUE==1 # True and 1 are are the same
FALSE==0 # False and zero are the same
!TRUE==FALSE # ~ takes the compliment of a test (flips the sign)
<- b==4 # Assigning result of logical test
c print(c)
!(b <= 4) # Is b less _greater_ than or equal to 4?
==5 | abs(a)==3 # OR
b==5 & abs(a)==3 # AND
b==3 & abs(a)==3 ) | c # Grouping (b
environment
bindings existing in a namespace
global environment
workspace
dropdown shows what exists globally
more on this later