I have two lists of dataframes: list1 and list2. Below is a sample data frame from list1 (df1) and list2 (df2):
> print(df1)
Moment.ext_multi.lane Moment.ext_single.lane Moment.int_multi.lane Moment.int_single.lane
Baseline 0.7109148 0.5367121 0.5874249 0.3718993
Sample1 0.7109148 0.5367121 0.5874249 0.3718993
Sample2 0.7109148 0.5367121 0.5874249 0.3718993
Sample3 0.7109148 0.5367121 0.5874249 0.3718993
Sample4 0.7109148 0.5367121 0.5874249 0.3718993
Sample5 0.7109148 0.5367121 0.5874249 0.3718993
Sample6 0.7109148 0.5367121 0.5874249 0.3718993
Sample7 0.7109148 0.5367121 0.5874249 0.3718993
Sample8 0.7109148 0.5367121 0.5874249 0.3718993
Sample9 0.7109148 0.5367121 0.5874249 0.3718993
Sample10 0.7109148 0.5367121 0.5874249 0.3718993
AASHTO 0.7550000 NA 0.6640000 0.4310000
Mean 0.7109148 0.5367121 0.5874249 0.3718993
> print(df2)
Shear.ext_multi.lane Shear.ext_single.lane Shear.int_multi.lane Shear.int_single.lane
Baseline 0.7109148 0.5367121 0.5874249 0.3718993
Sample1 0.7109148 0.5367121 0.5874249 0.3718993
Sample2 0.7109148 0.5367121 0.5874249 0.3718993
Sample3 0.7109148 0.5367121 0.5874249 0.3718993
Sample4 0.7109148 0.5367121 0.5874249 0.3718993
Sample5 0.7109148 0.5367121 0.5874249 0.3718993
Sample6 0.7109148 0.5367121 0.5874249 0.3718993
Sample7 0.7109148 0.5367121 0.5874249 0.3718993
Sample8 0.7109148 0.5367121 0.5874249 0.3718993
Sample9 0.7109148 0.5367121 0.5874249 0.3718993
Sample10 0.7109148 0.5367121 0.5874249 0.3718993
AASHTO 0.7550000 NA 0.6640000 0.4310000
Mean 0.7109148 0.5367121 0.5874249 0.3718993
I want to merge the two lists into a new list of data frames and remove all rown is all dataframes with rownames that are called "Mean": list3.
Then I would like to melt the data of the list such that the dataframes in the new list have 4 columns.
The first columns is Source and if the rownames of the originals lists list1 and list 2 are "Sample1" to "Sample10", then the Source indicates Samples, if the rowname is "baseline" then Source indicates Baseline, and if the row name is "AASHTO" then Source indicates AASHTO as well.
The second column is Type and is extracting the end of the column names (removing "Moment." and "Shear." from the begining and ".lane" from the end).
The third column is Moment and includes the values of list1.
The fourth column is Shear and includes the values of list1.
The expected sample dataframe (df3) from final list list3 is:
> print(df2)
Source Type Shear Moment
1 Baseline ext_multi 0.5367121 0.5874249
2 Baseline ext_single 0.5367121 0.5874249
3 Baseline int_multi 0.5367121 0.5874249
4 Baseline int_single 0.5367121 0.5874249
5 AASHTO ext_multi 0.5367121 0.5874249
6 AASHTO ext_single 0.5367121 0.5874249
7 AASHTO int_multi 0.5367121 0.5874249
8 AASHTO int_single 0.5367121 0.5874249
9 AASHTO int_single 0.5367121 0.5874249
5 Sample ext_multi 0.5367121 0.5874249
6 Sample ext_single 0.5367121 0.5874249
7 Sample int_multi 0.5367121 0.5874249
8 Sample int_single 0.5367121 0.5874249
9 Sample int_single 0.5367121 0.5874249
... continues