Rev 3279 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{TestRd}% Arithmetic -- Logic -- Extract -- formula -- Comparison}\title{Arithmetic / Logical Op.s / Extract .. / Formulae / Comparison}\usage{x + yx - yx * yx / yx ^ yx \%\% yx \%/\% y! xx & yx && yx | yx || yxor(x, y)x[i]x[i,j, ...]x[i,j, ... , drop=TRUE]x[[i]]x[[i,j, ...]]x$namey ~ modelformula(object)formula.default(anything)formula.formula(formula.obj)formula.terms(terms.obj)x < yx > yx <= yx >= yx == yx != y}\alias{Extract}\alias{Subscript}\alias{class<-}\alias{[}\alias{[[}\alias{$}\alias{+}\alias{-}\alias{*}\alias{/}\alias{^}\alias{\%\%}\alias{\%/\%}\alias{Arithmetic}\alias{!}\alias{&}\alias{&&}\alias{|}\alias{||}\alias{xor}\alias{Logic}\alias{~}\alias{formula.default}\alias{formula.formula}\alias{formula.terms}\alias{print.formula}\alias{<}\alias{<=}\alias{==}\alias{!=}\alias{>=}\alias{>}\alias{Comparison}\description{These operators act on logical vectors.\code{!} indicates logical negation (NOT).\code{&} and \code{&&} indicate logical AND and \code{|} and \code{||}indicate logical OR. The shorter form performs elementwisecomparisons in much the same way as arithmetic operators. The longerform evaluates left to right examining only the first element of eachvector. Evaluation proceeds only until the result is determined. Thelonger form is appropriate for programming control-flow.\code{xor} indicates elementwise exclusive OR.}\details{These operators are generic. You can write methods to handle subsettingof specific classes of data.The \code{[[} operator requires all relavent subscripts be supplied.With the \code{[} operator a comma separated blank indicates that allentries in that dimension are selected.When operating on a list the \code{[[} operator gives the specifiedelement of the list while the \code{[} operator returns a list withthe specified element(s) in it.The models fit by the \code{lm} and \code{glm} functionsare specified in a compact symbolic form.The \code{~} operator is basic in the formation of such models.An expression of the form \code{y~model} is interpretedas a specification that the response \code{y} is modelledby a linear predictor specified symbolically by \code{model}.Such a model consists of a series of terms separatedby \code{+} operators.The terms themselves consist of variable and factornames separated by \code{:} operators.Such a term is interpreted as the interaction ofall the variables and factors appearing in the term.In addition to \code{+} and \code{:}, a number of otheroperators are useful in model formulae.The \code{*} operator denotes factor crossing:\code{a*b} interpreted as \code{a+b+a:b}.The \code{^} operator indicates crossing to thespecified degree. For example \code{(a+b+c)^2}is identical to \code{(a+b+c)*(a+b+c)} which in turnexpands to a formula containing the main effectsfor \code{a}, \code{b} and \code{c} togetherwith their second-order interactions.The \code{\%in\%} operator indicates that the termson its left are nested within those on the right.For example \code{a+b\%in\%a} expands to theformula \code{a+a:b}.While formulae usually involve just variable and factornames, they can also involve arithmetic expressions.The formula \code{log(y)~a+log(x)} is quite legal.When such arithmetic expressions involveoperators which are also used symbolicallyin model formulae, there can be confusion betweenarithmetic and symbolic operator use.To avoid this confusion, the function \code{I()}can be used to bracket those portions of a modelformula where the operators are used in theirarithmetic sense. For example, in the formula\code{y~a+I(b+c)}, the term \code{b+c} is to beinterpreted as the sum of \code{b} and \code{c}.The generic function \code{formula} and its specificmethods provide a way of extracting formulaewhich have been included in other objects.An \R ``object'' is a data object which has a \code{class} attribute.A class attribute is a vector of character strings giving the names ofthe classes which the object ``inherits'' from. When a genericfunction \code{fun} is applied to an object with class attribute\code{c("first", "second")}, the system searches for a function called\code{fun.first} and, if it finds it, applies it to the object. If nosuch function is found, a function called \code{fun.second} is tried.If no class name produces a suitable function, the function\code{fun.default} is used.The function \code{class} prints the vector of names of classes anobject inherits from. Correspondingly, \code{class<-} sets theclasses an object inherits from.}\value{These binary operators perform arithmetic on vector objects.They return numeric vectors containing the result of the elementby element operations. The elements of shorter vectors are recycledas necessary. The operators are \code{+} for addition, \code{-} forsubtraction \code{*} for multiplication, \code{/} for division and\code{^} for exponentiation.\code{\%\%} indicates \code{x mod y} and \code{\%/\%} indicates integerdivision.Objects such as arrays or time-series can be operated on thisway provided they are conformable.}\seealso{\code{\link{Math}} for miscellaneous and \code{\link{Special}} for specialmathematical functions.\code{\link{list}}, \code{\link{array}}, \code{\link{matrix}}.}\examples{x <- 1:12; m <- matrix(1:6,nr=2); li <- list(pi=pi, e = exp(1))x[10] # the tenth element of xm[1,] # the first row of matrix mm[1, , drop = FALSE]# is a 1-row matrixli[[1]] # the first element of list liy<-list(1,2,a=4,5)y[c(3,4)] # a list containing the third and fourth elements of yy$a #the element of y named a##-------------------------------------------%%-- The following "\testonly{" is not properly treated [latex/html/nroff]:%% ===> ALL the following example text is doubled !!\testonly{cat("x <- c(1,4)\n x ^ 3 -10 ; outer(1:7,5:9)\n", file="xyz.Rdmped")}# parse 3 statements from the file "xyz.Rdmped"parse(file = "xyz.Rdmped", n = 3)x <- -1:12x + 12 * x + 3x \%\% 2x \%/\% 5y <- 1 + (x <- rpois(50, lambda=1.5) / 4 - 1)x[(x > 0) & (x < 1)] # all x values between 0 and 1if (any(x == 0) || any(y == 0)) "zero encountered"}}% this is extraneous! should give an error!\keyword{array}\keyword{list}