- Monday: Theory
- Warm-up Activity (10 min)
- Discussion on readings (40 min)
- Research design work (25 min)
- Project questions (remainder)
2026-03-30
https://019c932f-6501-a8d5-bac5-df7f6ede5a76.share.connect.posit.cloud/
##################################################### ## title: a new R script! ## author: you! ## purpose: to try out R ## date: today's date ##################################################### # you can start coding below
# what does R do with numbers? 2
## [1] 2
# what if we try adding or multiplying? 4+3
## [1] 7
53*2
## [1] 106
# what if we put all the previous results together? c(2, 3, 4+3, 53*2, 90*4/5)
## [1] 2 3 7 106 72
as.integer, as.numeric, as.character, as.logical)<, >, ==, !=, >=, <=) with different character and numeric values# what if we put all the previous results together?
matrix(c(2, 3, 4+3, 53*2, 90*4/5),
nrow = 5)
## [,1] ## [1,] 2 ## [2,] 3 ## [3,] 7 ## [4,] 106 ## [5,] 72
? sends you to the help page of whatever function follows it?matrix and then hit ctrl + entermatrix() functionc(your numbers here) inside? will give you more info on how a function works (i.e. ?matrix)list(c(2, 3, 4+3),
53*2,
90*4/5)
## [[1]] ## [1] 2 3 7 ## ## [[2]] ## [1] 106 ## ## [[3]] ## [1] 72
# assign "sum" to the sum of a few numbers penguin <- c(2, 3, 4+3, 53*2, 90*4/5) # now take a look at the result penguin
## [1] 2 3 7 106 72
# let's have R sum the numbers sum(c(2, 3, 4+3, 53*2, 90*4/5))
## [1] 190
# we'll call our function 'addition'
addition <- function(x, y){
return(x+y)
}
addition(2, 2)
## [1] 4
function(x))function(x,y))# try printing each of the first 10 numbers
for(i in 1:10){
print(i)
}
## [1] 1 ## [1] 2 ## [1] 3 ## [1] 4 ## [1] 5 ## [1] 6 ## [1] 7 ## [1] 8 ## [1] 9 ## [1] 10
i?1:10?# vector with 1-10 ten <- c(1:10) # try adding one ten + 1
## [1] 2 3 4 5 6 7 8 9 10 11
# vector with 1-10 ten <- c(1:10) sapply(ten, function(x) x + 1)
## [1] 2 3 4 5 6 7 8 9 10 11
#’s