#A vector called v1 that contains the values 1 to 12. v1<-c(1:12) #Adding the values 13 to 16 to the end of v1. v1<-c(v1[1:12],13:16) #A new vector v2 that contains the 1st to 7th and 12th to 16th #elements of v1. v2<-c(v1[1:7],v1[12:16]) #Adding V1+v2 - Explanation of error: once R has added the vectors together # up to the same corresponding length, it will then recycle the shorter vector (v2) # starting back at the first index v1+v2 # A new vector v3 by selecting all even elements of v1 v3<-subset(v1,v1%%2==0) #A matrix m1 with 4 rows from vector v1. m1<-matrix(v1,nrow=4) #A matrix m2 with 3 columns from vector v2. m2<-matrix(v2,ncol=3) #A new matrix m3 from m1 and m2 where m3 contains all of the #columns of both source matrices m3<-cbind(m1,m2) #Displays matrix m3 m3 #Labeling the columns of m3 colnames(m3)<-c("a","b","c","d","e","f","g") #Remove row 3 from m3 m3<-m3[-3,] #Calculate and displays means of each column. apply(m3,2,mean) #A barplot of row 1 of m3. barplot(m3[1,])