# SOME OPERATIONS WITH NUMERICAL VECTORS AND LOGICAL VECTORS x <- c(-5,0,7,-6,14,27) # data vector x x[1] # prints first element of x x[length(x)] # prints last element of x x[i] # the ith entry if 1<=i<=n, NA if i>n, all but # the ith if -n<=i<=-1, an error if i < -n, and # an empty vector if i=0 x[c(2,3)] # the second and 3rd entries x[-c(2,3)] # all but the seccond and third entries x[i] <- 5 # assign a value of 5 to the first entry; # also can use x[i] = 5 x[c(1,4)] <- c(2,3) # assign values to the first and fourth entries x[indices] <- y # assign to those indices indicated by the values # of INDICES: if y is not long enough, values # are recycled; if y is too long, just its initial # values are used and a warning is issued x < 3 # vector with length n of TRUE or FALSE # depending if x[i] < 3 which(x<3) # which indices correspond to the TRUE values # of x<3 x[x<3] # the x values when x<3 is TRUE -- same as x[which(x<3)]