sq(x)
x | Numeric or complex (vectors are legal). Missing values are ok also. |
This function doesn't use "^" function. So if that has been redefined, sq() will still generate a traditional square.
This function doesn't require any other hand-written functions. It only uses "*" so unless that is redefined, it will do the right thing.
sq(7) sq(3+5i) sq(1:10)
sq <- function(x) { y <- x*x; return(y); }