sign Function in R (Example)
In this R tutorial you’ll learn how to find out if a numeric value is positive or negative.
The post looks as follows:
Here’s how to do it.
Definition & Basic R Syntax of sign Function
Definition: The sign R function returns the signs of numeric elements. The value 1 is returned for positive numbers, the value 0 is returned for zero, and the value -1 is returned for negative numbers.
Basic R Syntax: You can find the basic R programming syntax of the sign function below.
sign(5) # Basic R syntax of sign function
In the remaining tutorial, I’ll illustrate in an example how to apply the sign function in the R programming language.
Example: Return whether Number is Positive or Negative
The R programming syntax below illustrates how to use the sign() command in the R programming language. Within the sign function, we simply need to specify a vector of numeric values:
sign(-2:5) # Apply sign function # -1 -1 0 1 1 1 1 1
The first two elements of our vector are negative (indicated by -1), the third element is zero (indicated by 0), and the remaining elements are positive (indicated by +1).
Video & Further Resources
Would you like to know more about the sign function? Then you could watch the following video which I have published on my YouTube channel. In the video, I show the content of this post.
Furthermore, you may read the other tutorials which I have published on this homepage.
- How to Calculate an Absolute Value
- Square Root in R
- R Functions List (+ Examples)
- The R Programming Language
In summary: In this article you learned how to apply the sign function in R. In case you have additional questions, please tell me about it in the comments section.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






