as.rectangular
Uniform Rectangular Data Functions
Description
Functions that allow you to access all rectangular data objects in
the same way. Rectangular data objects include matrices, data frames
and vectors.
Usage
as.rectangular(x)
as.char.rect(x)
is.rectangular(x)
subscript2d(x,i,j)
subscript2d(x,i,j) <- value
numRows(x)
numRows(x) <- value
numCols(x)
numCols(x) <- value
rowIds(x)
rowIds(x) <- value
colIds(x)
colIds(x) <- value
Arguments
x |
the object to be converted to rectangular data (as.rectangular), or a
rectangular data object.
|
i |
the first (row) subscript.
|
j |
the second (column) subscript.
|
value |
the object to be assign to x
|
Details
subscript2d, numRows, numCols, rowIds,
colIds can also be used on the left side of assignments. The value can be a character vector, or anything that
can be coerced to a character vector.
- subscript2d is for subscripting. When subscript2d is used in an assignment, it does not allow subscript replacement
outside the bounds of x. Instead, set numRows or
numCols first.
- When numRows or numCols is used in
an assignment, the row and column IDs are maintained
to have the correct length. Usually, this is done by setting numRows on the ID vector,
but for some objects (for example, data frames)
this might not be appropriate, and they have their own methods.
- Functions colnames<- and rownames<- simply call
colIds<- and rowIds<-, respectively.
- as.rectangular converts any object to a rectangular
data object (usually a data frame), if possible.
- is.rectangular tests whether an object is rectangular.
- numRows and numCols count the number of rows and columns.
- rowIds and colIds (and rownames and
colnames) return the row and column names or other
identifiers attached to rows and columns.
- colnames and rownames return the same values as
colIds and rowIds, respectively, if do.NULL=T.
- Instead of using names to replace row names from a matrix,
use rowIds or dimnames.
- The functions colnames, rownames,
colnames<-, rownames<- emulate R
functions of the same names.
Value
as.rectangular | returns x if it is already rectangular, or
as.data.frame(x) if it is not. |
as.char.rect | takes a rectangular object and returns a rectangular object
(vector or matrix) consisting of character strings, suitable for printing
(but not formatted to fixed width). |
is.rectangular | returns TRUE if x is rectangular, and FALSE if it is not. |
subscript2d(x,i,j) | is like x[i,j,drop=F], except that it allows
x[,1] (for example) for atomic vectors.
Usually, it returns an object of the same class as x
(this is not appropriate for some objects, such as "bs" objects).
It does not support a drop argument. |
numRows and numCols | return integers, like nrow and ncol,
except that they also work on atomic vectors (numRows returns
the length of the vector, and numCols returns 1). |
rowIds and colIds | return the IDs of the rows and columns.
These are often character vectors, but need not be,
depending on the class of x.
They are like the components of dimnames,
except that for named vectors, rowIds returns or sets the names
and colIds returns NULL. |
colnames and rownames | return the same values as
colIds and rowIds, respectively. |
See Also
Examples
x <- 1:10
y <- list(a=1:10, b=11:20)
is.rectangular(x)
y <- as.rectangular(y)
subscript2d(x,3,1)
subscript2d(y,4,1) <- 55
numRows(x)
numCols(y) <- 3
rowIds(x) <- letters[1:10]
colIds(y)
z <- cbind(1,1:4)
colnames(z)
colnames(z) <- colnames(z)
rownames(z) <- rownames(z)