[R] Meaning of following function

Matt Shotwell shotwelm at musc.edu
Sun Aug 1 21:05:37 CEST 2010


Ron,

In arithmetic, '-' and '+' are binary _and_ unary operators. That is,
both -1 and 1-1 are valid arithmetic expressions, the former negates its
argument, and the latter subtracts the second from the first. Since much
of R is designed do arithmetic, R honors the unary _and_ binary versions
of '-' and '+'. The implementation of `-`() performs negation when the
second argument is missing, and subtraction when both arguments are
present. AFAIR, the only other unary (but never binary) operator in R is
'!', or the 'NOT' operator (maybe also the one-sided formula operator
'~').

In contrast, the 'times' or 'multiply' operator '*' is generally a
binary operator in arithmetic. Hence, the function `*`() requires two
arguments.

-Matt



On Sun, 2010-08-01 at 10:56 -0400, Ron Michael wrote:
> Hi friends, I am aware of the function "-"() which acts as minus in ordinary computations. For example:
>  
> > "-"(3, 1)
> [1] 2
> 
> However what is the meaning of 
> > "-"(3)
> [1] -3
> 
> I was expecting R to generate some error as it does for "*"(3). What is the logic for that calculation?
>  
> Thanks,
> 
> 
> 	[[alternative HTML version deleted]]
> 

-- 
Matthew S. Shotwell
Graduate Student 
Division of Biostatistics and Epidemiology
Medical University of South Carolina



More information about the R-help mailing list