Extra work remaining from last week: show pixel pic

library(pixmap)
casablanca_pic <- read.pnm("casablanca.pgm")
casablanca_pic
plot(casablanca_pic)

dim(casablanca_pic@grey)

<aside> šŸ’” locator() Reads the position of the graphics cursor when the (first) mouse button is pressed

</aside>

Func on numeric vectors

Untitled

Element-Wise Operators

Untitled

<aside> šŸ’” Recycling: when a shorter vector is added to a longer one, the elements in the shorter vector are repeated

vā†c(1,3,5) v + c(1,3) [1] 2 6 6

</aside>

Func for numeric matrices

Untitled

# For thr line of best fit, y = a + bx (y, a, b are vectors)

dev_x <- x- mean(x)
dev_y <- y- mean(y)

Sxy <- sum(dev_x * dev_y)
Sxx <- sum(dev_x * dev_x)

# the estimated slope
slope <- Sxy/Sxx

# the estimated intercept
inter <- mean(y) - slope*mean(x)

abline(a = inter, b = slope)