2 + 2
## [1] 4
print("Hello")
## [1] "Hello"
"Hello"
## [1] "Hello"
'Hello'
## [1] "Hello"
num1 <- 5
num2 <- 10
num1 + num2
## [1] 15
var1 <- var2 <- var3 <- "Orange"
var1
## [1] "Orange"
var2
## [1] "Orange"
var3
## [1] "Orange"
text1 <- "R is"
text2 <- "awesome"
paste(text1, text2)
## [1] "R is awesome"
my_var <- 30
my_var <- "Sally"
my_var
## [1] "Sally"
x <- 10.5
class(x)
## [1] "numeric"
y <- 1000L
class(y)
## [1] "integer"
z <- 9i + 3
class(z)
## [1] "complex"
a <- "R is exciting"
class(a)
## [1] "character"
b <- TRUE
class(b)
## [1] "logical"
thismatrix <- matrix(c(1,2,3,4,5,6), nrow=3, ncol=2)
thismatrix
##      [,1] [,2]
## [1,]    1    4
## [2,]    2    5
## [3,]    3    6
thismatrix <- matrix(c("apple", "banana", "cherry", "orange"), nrow=2, ncol=2)
thismatrix[1,2]
## [1] "cherry"
length(thismatrix)
## [1] 4
x <- 10.5
y <- 55
x
## [1] 10.5
y
## [1] 55
class(x)
## [1] "numeric"
class(y)
## [1] "numeric"
c <- 1000L
d <- 55L
c
## [1] 1000
d
## [1] 55
class(c)
## [1] "integer"
class(d)
## [1] "integer"
e <- 3+5i
f <- 5i
e
## [1] 3+5i
f
## [1] 0+5i
class(e)
## [1] "complex"
class(f)
## [1] "complex"
sqrt(16)
## [1] 4
max(5, 10, 15)
## [1] 15
min(5, 10, 15)
## [1] 5
str <- "Hello World!"
nchar(str)
## [1] 12
str1 <- "Hello"
str2 <- "World"
paste(str1, str2)
## [1] "Hello World"
a <- 10
b <- 9
a > b
## [1] TRUE
2^5
## [1] 32
10 > 9
## [1] TRUE
10 == 9
## [1] FALSE
10 < 9
## [1] FALSE
5 %% 2
## [1] 1
a <- 33
b <- 200
if (b > a) {
  print("b is greater that a")
}
## [1] "b is greater that a"
i <- 1
while (i < 6) {
  print(i)
  i <- i + 1
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
fruits <- list("apple", "banana", "cherry")
for (x in fruits) {
  print(x)
}
## [1] "apple"
## [1] "banana"
## [1] "cherry"
adj <- list("red", "big", "tasty")
fruits <- list("apple", "banana", "cherry")
for (x in adj) {
  for (y in fruits) {
    print(paste(x, y))
  }
}
## [1] "red apple"
## [1] "red banana"
## [1] "red cherry"
## [1] "big apple"
## [1] "big banana"
## [1] "big cherry"
## [1] "tasty apple"
## [1] "tasty banana"
## [1] "tasty cherry"
my_function <- function() {
  print("Hello World!")
}
my_function()
## [1] "Hello World!"
my_function <- function(x) {
  return(5 * x)
}
print(my_function(3))
## [1] 15
print(my_function(5))
## [1] 25
print(my_function(9))
## [1] 45
nested_function <- function(x, y) {
  a <- x + y
  return(a)
}
nested_function(nested_function(2,2), nested_function(3,3))
## [1] 10
numbers <- c(1, 2, 3)
numbers
## [1] 1 2 3
fruits <- c("banana", "apple", "orange", "mango", "lemon")
numbers <- c(13, 3, 5, 7, 20, 2)
sort(fruits)
## [1] "apple"  "banana" "lemon"  "mango"  "orange"
sort(numbers)
## [1]  2  3  5  7 13 20
fruits <- c("banana", "apple", "orange")
length(fruits)
## [1] 3
thislist <- list("apple", "banana", "cherry")
thislist
## [[1]]
## [1] "apple"
## 
## [[2]]
## [1] "banana"
## 
## [[3]]
## [1] "cherry"
length(thislist)
## [1] 3
data_frame <- data.frame(
  training = c("strength", "stamina", "other"),
  pulse = c(100, 150, 120),
  duration = c(60, 30, 45)
)
data_frame
thisarray <- c(1:24)
thisarray
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
multiarray <- array(thisarray, dim = c(4,3,2))
multiarray
## , , 1
## 
##      [,1] [,2] [,3]
## [1,]    1    5    9
## [2,]    2    6   10
## [3,]    3    7   11
## [4,]    4    8   12
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,]   13   17   21
## [2,]   14   18   22
## [3,]   15   19   23
## [4,]   16   20   24
plot(1, 3)

plot(c(1, 8), c(3, 10))