I am having a bit of trouble converting a data frame to an array.
I am doing EEG analysis, and I want to use an R package that uses array as its default data table for some computations. However, what I have is a data frame. Here's the example of my data frame.
I would like to ask how can I format this into an array, with the headers of the data frame as the start, similar to this, plus the number/ range of items beside the class (e.g. char or factor).
I tried using the array() function but it did not work, the class was still a "data frame", the headings were gone and no number how many there are.
I would appreciate any help regarding this matter. Thank you!
SRE:
So, I have all the dataset as about a participants' ID, electrodes (channel), hemisphere (part of the brain) and some stimuli components (segment, class, type),time and amplitude of the effect I needed. Basically the data frame looks like this:
> data_eeg_long
# A tibble: 2,496,000 x 9
ID timing channel hemisphere segment stimclass pairtype time ampl
<fct> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl>
1 01 long Fp1 left Ref Arm Df -100 -0.776
2 01 long Fz center Ref Arm Df -100 -0.219
3 01 long F3 left Ref Arm Df -100 -0.356
Now, I want to use this package command to get the GFP for these values. However, it needs to be an array (such as what I have shown in Figure 2) or a numerical matrix. However, when I try to convert these to an array using the following:
> eeg_long_array <- array(data_eeg_long, dimnames= eeg_long_matrix[1,])
> head(eeg_long_array)
1 01 long Fp1 left Ref Arm Df -100 -0.7756
2 01 long Fz center Ref Arm Df -100 -0.2190
3 01 long F3 left Ref Arm Df -100 -0.3563
4 01 long F7 left Ref Arm Df -100 -0.6495
5 01 long FT9 left Ref Arm Df -100 -0.4021
6 01 long FC5 left Ref Arm Df -100 -0.3363
> class(eeg_long_array)
[1] "data.frame"
And it looks like this in my environment:
It still does not work. The output I expect is similar to the Figure 2 I showed, but I just cannot figure out how. I am new to this package, but it's the only one available that can make the computation I need.