8  Vectors

8.1 Quiz: Vectors I

To create the following sequence of numbers

0.2, 0.4, 0.6, ..., 1.2

we can use:

0.2:1.2

seq(0.2, 1.2)

seq(0.2, 1.2, by = 0.2)

seq(0.2, 1.2, length.out = 6)

Recall that : operator creates sequences in steps of 1 or -1.

Recall that : operator creates sequences in steps of 1 or -1. To create sequences with different steps you should use the seq() function.

8.2 Quiz: Vectors II

What is the result of executing:

c(1, NULL, 3)

NULL

1, 3

1, NULL, 3

1, NA, 3

NULL values are not the same as NA.

NULL represents the null object in R. You cannot create a vector with nulls, or insert a NULL into a vector if you try the vector will be created without the NULL.

8.3 Exercise: Vectors III

x <- c(1, 3)
x
[1] 1 3

What happens when you try to combine NULL to x?

Why?

8.4 Exercise: Vectors IV

Calculate the variance of the sequence of integer numbers from 1 to 10, and assign the result to the variable a.

If you need search the help for variance to identify the function to use.

8.5 Exercise: Vectors V

# y contains 20 random numbers from a Normal distribution
# with zero mean and standard deviation 1
set.seed(123)
y <- rnorm(20)
y
 [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
 [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197  1.22408180  0.35981383
[13]  0.40077145  0.11068272 -0.55584113  1.78691314  0.49785048 -1.96661716
[19]  0.70135590 -0.47279141

Filter all observations from y that are greater than or equal to 0.5, and attribute the result to the variable fy.