Learn R Programming

MRIaggr (version 1.1.5)

array2df: Array to data.frame converter

Description

Convert observations stored in the array format into the data.frame format.

Usage

array2df(array, coords = NULL, name_newparam = "res", names_coords = letters[9:(8+ncol(coords))], na.rm = TRUE)

Arguments

array
the array that should be converted into a data.frame. array or matrix. REQUIRED.
coords
the spatial coordinates of the observations contained in array. matrix or NULL.
name_newparam
the name of the contrast parameter to which cooresponds array. character.
names_coords
the name of the coordinates. character vector.
na.rm
should observations with missing values be removed ? logical.

Value

A dataframe with in columns the coordinates and the parameter values, and in rows the observations.

Details

ARGUMENTS : If coords is set to NULL, the coordinates will be defined by the position of the observations in array. If na.rm is set to TRUE, the coord argument will only contains the coordinates of the non-NA observations of array.

Examples

Run this code
## load a NIFTI file (array format)
path.Pat1 <- system.file(file.path("nifti"), package = "MRIaggr")
nifti.Pat1_TTP_t0 <- readMRI(file.path(path.Pat1, "TTP_t0"), format = "nifti")
dim(nifti.Pat1_TTP_t0)

## conversion to data frame format
res128 <- array2df(array = nifti.Pat1_TTP_t0, name_newparam = "TTP_t0")
dim(res128)
head(res128)

## conversion to data frame format with specific coordinates
res256 <- array2df(array = nifti.Pat1_TTP_t0, name_newparam = "TTP_t0",
                   coords = expand.grid(129:206, 129:228, 1:3, 1))
dim(res256)
head(res256)

Run the code above in your browser using DataLab