#Christine Woods. 1704446. ACCA5021 #Statistical Programming Data Manipulation in R v1<-c(1:12) #create a vector that contains the values 1 to 12 v1 #display v1 v1<-c(v1,13:16) #Add the values 13-16 to the end of V1 v1 #display v1 v2<-c(1:7,12:16) #Create a new vector v2 that contains the 1st-7th and 12th-16th elements of v1 v2 #display v2 v1+v2 #This has created a warning because R adds different length vectors vertically, if they #are not the same length the programme will loop around back to the first column and add #number i.e once the loop gets to 13 there is no corresponding number so it loops back #round to the number 1. v3<-v1%%2==0 #Create a new vector v3 by selecting all even elements of v1 using a filter with True #or false reply v3 #display v3 v3<-ifelse(v1%%2==0,"yes","no") #Creates the results show with a Yes or No result v3 #display v3 m1<-matrix(c(v1),nrow=4, byrow=T) #Create a matrix m1 with 4 rows from vector v1. m1 #Displays m1 m2<-matrix(c(v2),nrow=4,ncol=3) #Create a matrix m2 with 3 columns from vector v2. m2 m3<-cbind(m1,m2) #Create and display a new matrix m3 from m1 and m2 where #m3 contains all of thecolumns of both source matrices. m3 #Dispmay M3 colnames(m3)<-c('a','b','c','d','e','f','g') #Label the columns of m3 as "a", "b", "c", "d", #"e", "f" and "g". m3 #Display m3 m3<-m3[-3,] #Remove row 3 from m3. m3 #Display m3 apply(m3,2,mean) #Calculate and display the means of each column. barplot(m3[1,]) #Create a barplot of row 1 of m3.