Load data in the workspace by executing:

source("http://www3.nd.edu/~steve/computing_with_data_2014/3_Vectors/work_along_data_S3.R")

Vector Attributes

What is the length of x?

length(x)
## [1] 47

What is the class of x?

class(x)
## [1] "numeric"

What is the name of the 4th entry in x?

names(x)[4]
## [1] "N4"

What are the mean, median and 3rd quartile of x?

summary(x)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -4.15900 -1.24300  0.25190 -0.04026  1.38500  3.08500

Logical vectors

What are the possible values for an entry of y?

class(y)
## [1] "logical"

Since y is logical, the possible values for an entry in y are either True or False.

How many of each value are there? For True, T, the sum function returns the number of True’s in y:

T<-c(sum(y))
T
## [1] 12

For False, F, we subtract the number of True’s from the total number of values in y.

F<- c(length(y)-sum(y))
F
## [1] 6

How many entries in x are less than 0?

X<-c(length(x[x<0]))
X
## [1] 21

Subsetting

Form a new vector of all entries in x greater than the median.

x_median<-c(x[x>median(x)])

Missing Data

What is the sum of v1?

sum(v1)
## [1] 28

What is the sum of v2?

sum(v2, na.rm= TRUE)
## [1] 17