R-Cheatsheet
install.packages('package_name')
library(package_name) #notice - no quotes
a = 10
b = "hello"
c <- "similar to above one" # "<-" is similar to '='
10 + 11
19 * 7
7 / 3
5 ^ 3 #125 - exponential
5 ** 3 #125 - exponential
8 %% 5 #3 - %% indicates x mod y (“x modulo y”)
8 %/% 5 #1 - Integer Division
if (condition){
Do something
} else {
Do something different
}
for (variable in sequence){
Do something
}
for (i in 1:3){
print(i)
}
1
2
3
while (condition){
Do something
}
while (i < 10){
print(i)
i = i + 1
}
v <- c(2, 4, 6) # 2, 4, 6
2:6 # 2, 3, 4, 5, 6
- Length
length(v)
- Indexing
v[1:3]
- Boolean
all(v)
any(v)
df <- data.frame(col1 = v1, col2 = v2)