[R] sqrt(-x) vs. -x^0.5

cberry at tajo.ucsd.edu cberry at tajo.ucsd.edu
Thu Mar 22 04:57:51 CET 2012


Mike Williamson <this.is.mvw at gmail.com> writes:

> Thanks Sarah, All,
>
>     I guess I never thought of a negative sign as an "operation", but
> knowing that it is considered an operation explains everything nicely.
>  Somewhere in it's underbelly, I suppose -4 is represented as "0 - 4"?

Not exactly. Here is the list of constituent elements of expressions for -1 and 0 - 1

> as.list(quote(-4))
[[1]]
`-`

[[2]]
[1] 4

> as.list(quote(0-4))
[[1]]
`-`

[[2]]
[1] 0

[[3]]
[1] 4

The first case is unary, the second is binary. 

Exercise: See ?Syntax. Write the result of this line:

          lapply( as.list( quote(-1-4) ), as.list )

and (thereby) explain why the result of -1-4 isn't 3.

HTH,

Chuck

[rest deleted]


-- 
Charles C. Berry                            Dept of Family/Preventive Medicine
cberry at ucsd edu			    UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list