Learn R Programming

EFDR (version 1.3)

df.to.mat: Change xyz data-frame into a Z image

Description

Given a data frame with fields x, y and z, df.to.mat uses the x and y coordinates to rearrange z into a rectangular matrix image Z.

Usage

df.to.mat(df)

Value

matrix image

Arguments

df

data frame with fields x, y and z

Details

This function requires that all pixels in the image are defined, that is df$x and df$y must be the column outputs of the function expand.grid(x0,y0) where x0, y0 are axes values. Note that x0 and y0 do not need to be regularly spaced.

Examples

Run this code
df <- data.frame(expand.grid(1:10,1:10))
names(df) <- c("x","y")
df$z <- rnorm(nrow(df))
Z <- df.to.mat(df)

Run the code above in your browser using DataLab