Multi-dimensional data structure management in R

Viewed 98

I have a concern about data organisation and the best approach to simplify some multi-layered data. Simply, I have a 10 replicates of small wood beams (BeamID, ~10) subjected to a 10 different treatment (TreatID, ~10), and each beam is load tested which produces a series data of a Load with consequent Displacement (ranging from 10 to 50 rows per test; I have code that corrects for disparities in row length). Each wood beam is tested multiple times (Rep, ~10).

My plan was to lump all this data into a 5-D array:

Array[Load, Deflection, BeamID, TreatID, Rep]

This way, I should be able to plot the load~deflection curves for a given BeamID, TreatID, for all Reps by using Array[ , ,1,1, ], right? So the hypothetical output for Array[ , ,1,1,1], would be:

+------------+--------+-----+
| Deflection |  Load  | Rep |
+------------+--------+-----+
| 0          | 0      |   1 |
| 6.35       | 10.5   |   1 |
| 12.7       | 20.8   |   1 |
| 19.05      | 45.3   |   1 |
| 25.4       | 75.2   |   1 |
+------------+--------+-----+

And Array[ , ,1,1,2] would be:

+------------+--------+-----+
| Deflection |  Load  | Rep |
+------------+--------+-----+
| 0          | 0      |   2 |
| 7.3025     | 12.075 |   2 |
| 14.605     | 23.92  |   2 |
| 21.9075    | 52.095 |   2 |
| 29.21      | 86.48  |   2 |
+------------+--------+-----+

Or I think I could keep it as a simpler, 'melted' dataframe, which would have columns for Load and Deflection, and BeamID, TreatID, and Rep would be repeated for each row of the test output.

+------------+--------+-----+--------+---------+
| Deflection |  Load  | Rep | BeamID | TreatID |
+------------+--------+-----+--------+---------+
| 0          | 0      |   1 |      1 |       1 |
| 6.35       | 10.5   |   1 |      1 |       1 |
| 12.7       | 20.8   |   1 |      1 |       1 |
| 19.05      | 45.3   |   1 |      1 |       1 |
| 25.4       | 75.2   |   1 |      1 |       1 |
| 0          | 0      |   2 |      1 |       1 |
| 7.3025     | 12.075 |   2 |      1 |       1 |
| 14.605     | 23.92  |   2 |      1 |       1 |
| 21.9075    | 52.095 |   2 |      1 |       1 |
| 29.21      | 86.48  |   2 |      1 |       1 |
+------------+--------+-----+--------+---------+

However, with the latter, I'm not sure how I could easily and discretely pull out all the Rep test values for a specific BeamID and TreatID, especially since I use a linear model to fit a 3rd order polynomial for an specific test to extract the slope of the curves. Having it as a continuous dataframe means I'd have to specify starting and stopping points to start the linear model, correct?

Thoughts, suggestions? Am I headed in the right direction in using a 5-D array? R is a new programming language for me, so please pardon my misunderstandings.

0 Answers
Related