Description Usage Arguments Details Value See Also Examples
View source: R/array_transform.R
array2df
transforms an array to a data.frame
1 2 3 4 5 6 7 8 9 |
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 |
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: |
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 |
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.
The function returns a data.frame.
autoConvert
for coercion, and
transformArray
for a higher-level version of array2df
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.