The first steps

Logarithm

the logarithm of a number is the exponent to which another fixed number, the base, must be raised to produce that number

\(\log_2 8 = 3\)

\(2^3 = 8\)

Do not confuse == with = or <-!

Atomic vector

Atomic vector

Coercion

У R есть иерархия coercion: NULL < raw < logical < integer < double < complex < character < list < expression

Task

Create a vector:

vv <- 11:30

Return only even numbers from it!

Solutions

vv[c(2,4,6,8,10,12,14,16,18,20)]
##  [1] 12 14 16 18 20 22 24 26 28 30
vv[1:10*2]
##  [1] 12 14 16 18 20 22 24 26 28 30
vv[c(FALSE, TRUE)]
##  [1] 12 14 16 18 20 22 24 26 28 30

Task

Create a vector:

vv <- c(1:4, 56:53, 13:16)

Return values that are more than the mean of this vector!

Solution

vv[vv>mean(vv)]
## [1] 56 55 54 53

Task

Try to calculate the mean of this vector (without NA!)

There are at least two solutions!

Solutions

mean(vv[!is.na(vv)])
## [1] 20.90909
mean(vv, na.rm = TRUE) #Read help!
## [1] 20.90909

Matrices

Conclusion

Thank you!