- Daróczi Gergely honlapja - -

2. hét

Egyszerű számítások:

1 + 3
3^3
pi
sqrt(100)
sin(0)
sin(pi)

Megjelenítés:

plot(sin)

2D vektorok:

x <- c(1, 3)
x
y <- c(2, 6)
y
plot(x, y)

Valóban ezeket a vektorokat határoztuk meg?

Vektorműveletek:

x*3
y/2
x+y
x*y
c(1*2, 3*6)

Vektorok szorzása:

x %*% y
1*2 + 3*6

Mátrixok:

m <- cbind(x, y)
m
plot(m)
m <- rbind(x, y)
m
plot(m)
 
t(m)

További mátrixok:

x <- c(1, 3, 6)
y <- c(2, 6, 8)
plot(x, y)
 
x*pi
y^3
x*y
c(1*2, 3*6, 6*8)
x %*% y
1*2 + 3*6 + 6*8
 
m <- cbind(x, y)
m
m <- rbind(x, y)
m
plot(m)

Visszatérünk a szinuszgörbéhez:

x <- 1:100/10
x <- seq(0, 20, by=0.1)
y <- sin(x)
plot(x,y)
plot(x,y, type = 'l')

“Élő” mátrixok:

mtcars
?mtcars
 
mtcars$hp
mtcars[, 'hp']
str(mtcars)
mtcars[, 4]
mtcars[1, 4]
mtcars
mtcars[1,1]

Oszlopvektorok:

mtcars$qsec
min(mtcars$qsec)
max(mtcars$qsec)
range(mtcars$qsec)
mtcars$mpg
mtcars$mpg
min(mtcars$mpg)
max(mtcars$mpg)
range(mtcars$mpg)
(x <- mtcars$qsec / mtcars$mpg)
min(x)
max(x)
range(x)
which(x == min(x))
mtcars[which(x == min(x)), ]
mtcars[which(x == max(x)), ]

Egy egyszerű modell:

plot(mtcars$qsec, mtcars$mpg)
abline(fit)
fit <- lm(mpg ~ qsec, data = mtcars)
fit
plot(mtcars$qsec, mtcars$mpg)
abline(fit, col = 'red')
predict(fit) - mtcars$mpg