Ops.data.frame
Ops Group Method for Data Frame Objects

Description

A group method defining mathematical operations on data frames.

Usage

e1 OP e2 
OP e1

Arguments

e1, e2 objects, at least one of which inherits from class "data.frame".

Details

If both arguments inherit from data frames, the operation is applied to the corresponding pairs of variables. The method is currently narrow minded about matching columns. If both arguments are data frames, they must match exactly in dimensions. This could easily be relaxed, but only by making a somewhat arbitrary decision about extending the shorter of the frames.
If one argument is a data frame and the other is not. The procedure depends on the mode of the other operand. If that operand is a list, the method tries to determine whether it is intended to be a single variable or to have one element per variable, by looking at its length. If the non-data-frame operand is not a list, it is assumed to be a vector or matrix to be used in the corresponding default operator. The data frame is converted to a matrix, and the default method for the operation is applied. This means, for example, that comparison operations are applied to character data if there are any non-numeric variables in the data frame. Arithmetic operations fail if there are any non-numeric variables (as they should).
This is a group method for the functions of the Ops group, the basic operators for arithmetic, comparison, and logic. While the method is not itself restrictive with regards to the kind of variable in the data frame, the inherited method applied to the columns likely fails for non-numeric variables and any of the arithmetic operators.
Value
returns a data frame, each column of which is the result of applying the operator to a corresponding variable from one or both of the arguments.
See Also
data.frame, Math.data.frame.object
Examples
df <- data.frame(x=1:7, y=c(2,3,5,7,11,13,17), z=c(1,1,2,3,5,8,13))
df + 42
log(df) / df
-df
Package base version 6.1.1-7
Package Index