# Creating and applying a function

# Define a matrix m

m<-matrix(c(1,2,3,4,5,6,7,8,9,10,11,12), nrow=3, byrow=T)

# Display m

m

# Create the function square to square 

square<-function(x) x*x

# Apply square() to m

apply(m, 1, square)

# Get the transpose of the result

t(apply(m, 1, square))

# Square works on matrices - does it work on vectors?

square(3)
square(2:4)
