title: How to square matrix elements in R using loops and apply function
body: <p>I have a 3x3 matrix that I have made in R. I am being asking to square all the numbers in the matrix. First using loops and then using the apply function. I have done the following already. </p>
  
  <pre><code>myMatrix = matrix ( c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3)
  </code></pre>
  
  <p>So that gives me my matrix. Then I used this to square them </p>
  
  <pre><code> myMatrix * myMatrix ##don't know how to make a loop to do this
  </code></pre>
  
  <p>And finally my attempt to use the apply() function to do the same thing</p>
  
  <pre><code>  apply(myMatrix, c(1,2), exp) ##this gave me numbers that didnt look correct
  </code></pre>
  
  <p>Any help in the right direction would be very nice.</p>
  
  <p>Thanks</p>