title: Trying to define a function in R but it turns out to be object instead
body: <p>im a student who are currently studying R, and my lecturer gives me an assignment from one of the notebooks, here are the question:</p>
  <p>We previously defined the generic power function and the instances square and cube this way:</p>
  <pre><code>power &lt;- function(n) function(x) x^n
  square &lt;- power(2)
  cube &lt;- power(3)
  </code></pre>
  <p>If you instead defined this:</p>
  <pre><code>power &lt;- function(x, n) x^n
  </code></pre>
  <p>How would you then define square and cube?</p>
  <p>with the 1st example both power,square,and cube would become a function, that can calculate a vector</p>
  <p>with <code>x= (1,2,3,4,5)</code>
  I tried solving the problem using a various of code combination such as</p>
  <pre><code>square=power(x,2) # it works, but it creates 'square' as an  object of x^2 instead of being a function,
  square=power(,2) # telling me that x has to be defined and cant be empty
  square= power(2) # I know it wouldn't work and it says n has to be defined which is... not a surprise
  </code></pre>
  <p>The book doesn't gives any example of this and I'm basically out of ideas on how to redefine the function, so any helps would be greatly appreciated, thanks for your attention!</p>