'NOOBQ- Can't create a function with two variables

w <- function(x,y) { 

  ((2*x*y+y^4)/(x^2))
                      
}  #Function we need to solve
w(5)

Error in w(5) : argument "y" is missing, with no default

This error occurs but y is a function too and i created y before but this error occurred again.

r


Solution 1:[1]

First of all, you need to set * to multiply in R like this:

w <- function(x,y) {
  
  (2*x*y+y^4)/(x^2)
  
}

The error says y is missing because you only give x a value. So if you want this function to work, you need to set a value for y for example w(5,1):

> w(5, 1)
[1] 0.44

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quinten