I have defined a simple function:
function1<-function(x){if (X<0) {-x} else {x}}
When attempting to call it with an argument, i.e.:
function1(1)
R yields:
"Error in function1(1) : object 'x' not found"
What is wrong? How it can be corrected?
I have defined a simple function:
function1<-function(x){if (X<0) {-x} else {x}}
When attempting to call it with an argument, i.e.:
function1(1)
R yields:
"Error in function1(1) : object 'x' not found"
What is wrong? How it can be corrected?
P.S. Before calling the function I have been also trying to assign in a seperate line of the code a value to the x, nevertheless the result has been the same, although the x is listed in the "Global Environment" panel in the R Studio.
R is case sensitive, and you are using X
and x
in your code as if they were the same.
It works now. Thank you.
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.