Good morning, I'm a student of statistics and I have to do this exercise : create a function for to calculate square of binomial. I have written binomio=function(z,y) {z^2+yz2+ y^2} But this function isn't correct when z is unknown. For exemple when i want to calculate (x+2)^2 and I would like as a result (x^2+22x+2^2) Please help me...It is one of the first times that I'm using R studio.
If I understand your question right, using the multiplication operator * between the variables may solve your problem.
*
binomio = function(z,y) {z^2+y*z*2+y^2} binomio(3,4) [1] 49