array2df: Transforms an array to a data.frame

Description Usage Arguments Details Value See Also Examples

View source: R/array_transform.R

Description

array2df transforms an array to a data.frame

Usage

1
2
3
4
5
6
7
8
9
array2df(
  dat,
  value_name = "values",
  value_dim = NULL,
  value_type = typeof(dat),
  auto_convert = FALSE,
  na_omit = FALSE,
  ...
)

Arguments

dat

a matrix or array

value_name

the name of the variable in the data.frame which contains the values of the input (default: "values"). If 'value_dim' is not NULL or character(0L), the name of the value-columns will start with 'value_name'.

value_dim

numeric or character index(es) of dimension(s) whose levels should be handled as separate measures. They appear as separate variables in the returned data.frame. The default is NULL, which means that one variable will contain all data points of the array.

value_type

a character value which specifies the type of the measure (default: typeof(dat)). Possible types are "logical", "character", "numeric", "double", "integer", "factor", "raw", "complex".

auto_convert

a logical value whether automatic conversion of dimension names (i.e., characters to numeric (if possible) or to factors) should be performed (default: FALSE).

na_omit

if TRUE, omit all rows from the data.frame which have missing values (default: FALSE)

...

named arguments passed to autoConvert if 'auto_convert' is TRUE

Details

By default, this function returns a data.frame with as many variables as the number of dimensions of the array, coding the levels of each dimension, plus an extra variable containing the values of the array. However, 'dat' might be an array of different measures, e.g. one of the dimensions might have two levels: 'weight' and 'height' which should appear as separate variables in the returned data.frame. If this is the case, one should provide the name or index of the given dimension in the argument 'value_dim'. If more dimensions are given in 'value_dim', all combinations of their levels will be returned as separate variables. The names of these variables will contain the character string as given in 'value_name', plus the concatenated names of the corresponding dimensions and dimension levels.

Value

The function returns a data.frame.

See Also

autoConvert for coercion, and transformArray for a higher-level version of array2df

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# example data
data(erps)

# transform to data.frame, change the default value name to "amplitudes"
str(array2df(erps, value_name = "amplitudes"))

# treat all dimensions as factors, except for the time dimension, which
# should be integer, and return the three levels of the stimulus class
# dimension in wide format (as separate variables)
str(array2df(erps, value_name = "amplitudes", value_dim = "stimclass",
             auto_convert = TRUE))

tdeenes/eegR documentation built on April 19, 2021, 4:17 p.m.