Reshaping to a crosstable {OceanView} | R Documentation |
Converts a dataset from database-format to a cross table
Description
Reshapes data arranged in 3 columns to a “crosstable” matrix.
Usage
db2cross (input, row = 1, col = 2, value = 3, subset = NULL,
df.row = NA, df.col = NA, out.row = NA, out.col = NA,
full.out = FALSE)
Arguments
input |
A |
row |
Number or name of the column in |
col |
Number or name of the column in |
value |
Number or name of the column in |
subset |
Logical expression indicating elements or rows to keep;
missing values are taken as |
df.row , df.col |
Maximal distance in row and column values that should
be considered the same. The default is to use each unique row or column
value in |
out.row , out.col |
Values of rows and columns to be used in the cross table.
The default is to use each unique row or column value in |
full.out |
If |
Details
Uses a simple fortran function.
rows and columns are generated by the unique values
in each
x- and y-column.
Value
a list containing:
x |
The values of the rows. |
y |
The values of the columns. |
z |
The crosstable, a matrix. |
and if full.out = TRUE
also
map |
The mapping of the x and y values, consisting of
|
Author(s)
Karline Soetaert <karline.soetaert@nioz.nl>
See Also
reshape, the official (slow) R-function
remap to remap a matrix or array to higher or lower resolution
Examples
## =======================================================================
## test the function on a small data set
## =======================================================================
df3 <- data.frame(school = rep(c("a","b","c"), each = 4),
class = rep(9:10, 6),
time = rep(c(1,1,2,2), 3),
score = rnorm(12))
head(df3)
db2cross(df3, val = 4)
## =======================================================================
## Defining the output rows
## =======================================================================
Samples <- data.frame(time = c(1, 1.1, 1.2, 2, 2.1, 2.2, 4, 4.1, 4.2),
var = rep(c("O2", "NO3", "NH3"), 3),
val = 1:9)
Samples
db2cross(Samples)
db2cross(Samples, df.row = 0.5)
db2cross(Samples, out.row = c(1, 2, 4))
db2cross(Samples, out.row = 1:4)
## =======================================================================
## A larger dataset; requires OceanView.Data
## =======================================================================
## Not run:
data (pp.aug2009.db)
crosstab <- db2cross(pp.aug2009.db)
crosstab$z[crosstab$z>1000] <- 1000
crosstab$z[crosstab$z<0] <- NA
image2D(z = crosstab$z, x = crosstab$x, y = crosstab$y,
main = "primary production august 2009 mgC/m2/d",
NAcol = "black")
## End(Not run)