get_data_frame
helps importing MNE data structures
get_data_frame(inst, picks = NULL, index = NULL, scaling_time = 1000, scalings = NULL, copy = T, start = NULL, stop = NULL, long_format = T)
inst | An instance of MNE data containsers, e.g,
|
---|---|
picks | A zero-indexed integer array, a string, list, slice or None. |
index | The columns to be uesed as pandas index. tuple of str or None. |
scaling_time | Scaling to be applied to time units. Float. |
scalings | Scaling to be applied to the channels picked. |
copy | Whether to make a copy of the data. |
start | If it is a Raw object, this defines a starting index for creating the dataframe from a slice. The times will be interpolated from the index and the sampling rate of the signal. Int or None. |
stop | If it is a Raw object, this defines a stop index for creating the dataframe from a slice. The times will be interpolated from the index and the sampling rate of the signal. Int or None. |
long_format | If True, the dataframe is returned in long format where each row is one observation of the signal at a unique coordinate of channels, time points, epochs and conditions. The number of factors depends on the data container. For convenience, a ch_type column is added when using this option that will facilitate subsetting the resulting dataframe. If False, mne-r is making sure that the channel names are cleaned from white spaces to esnure that the R-formulas will work. In the case that epochs are passed, the pandas muliti-index is unpacked and the columns "condition", "epochs", and "time" are prepended. Unliker the MNE-Python function, the default is True. |
Returns a data.frame. The layout depends on the options
(e.g. long_format
) and the type of instance
(e.g. Epochs vs Raw).
The code will call the .to_data_frame
method of the MNE
data container and returns a dataframe readily usable in R. Note
that the type definitions below refer to Python types. Please see
the reticulate documentation to learn about R-to-Python
conversion rules. Note that this function requires, next to
MNE, a working Pandas installation.
For background information on exporting MNE objects
to dataframes, consider the designated MNE
tutorial.
library(mne) fname <- paste(mne$datasets$testing$data_path(), "MEG", "sample", "sample_audvis_trunc_raw.fif", sep = "/") raw <- mne$io$read_raw_fif(fname, preload = T) raw_df <- get_data_frame(raw) print(head(raw_df))#> time channel observation ch_type #> 1 0 MEG 0113 -25.871327 grad #> 2 0 MEG 0112 13.109141 grad #> 3 0 MEG 0111 -14.532409 mag #> 4 0 MEG 0122 -27.734474 grad #> 5 0 MEG 0123 5.027347 grad #> 6 0 MEG 0121 -28.779105 mag