#Lowri Jones
#1801539

# 1.  Creating a vector v1 with the values 1 to 12.
v1 <- c(1,2,3,4,5,6,7,8,9,10,11,12)

#ANOTHER WAY
v1 <-c(1:12)

#Display
v1

# 2.  Adding numbers 13 to 16 onto the end of v1
v1 <- c(v1, 13,14,15,16)

#ANOTHER WAY 
v1 <-c(v1, 13:16)


# 3. Using V1, create a vector V2 containing 1st-7th and 12th-16th values
v2 <-c(v1[1:7], v1[12:16])

# 4. Adding v1 and v2 together
v1 + v2
# EXPLANATION - It adds the first two numbers in the vector together (1+1=2 and so on)
# It carrys on to add as many numbers together as it can and when it gets to
# the final value in V2 (as this is the shortest length vector) it reuses the
# starting first 5 values from v2 adding them to the remaining v1 vector values.

# 5. Create a vector v3 containing all even elements of v1
v3<- v1[v1%%2==0]
v3

# 6. Create a matrix m1 with 4 rows from vector v1
m1<- matrix(c(v1), nrow=4)

# 7. Create a matrix m2 with 3 collumns from vector v2
m2<- matrix(c(v2), ncol=3)

# 8. Create and display a new matrix m3 from m1 and m2 where m3 contains all of the collumns from both source matrices
m3<- matrix(c(m1, m2), ncol=7)

#9. Rename all of the columns as a,b,c,d,e,f,g
colnames(m3)<-c("a","b","c","d","e","f","g")

# 10. Remove row 3 from m3
m3<-m3[-3,]

# 11. Calculate and display the means of each column
mean(m3[,1:7])


# 12. Create a barplot of row 1 of m3 
hist(m3[1,], breaks=12)