I am trying to add new columns in a dataframe based on the dataframe names.
So I have this list of dataframes called df_list, in this list are dataframes called
(1.3.A), (2.3.A), (1.5.A), (2.5.A), (1.3.B), (2.3.B), (1.5.B)
Each of these letter and numbers are important in the data. For example, all dataframes with a name that starts with "1" are from trial 1 of the experiment and those that end in A are from group A.
Can someone suggest how I can add a new column in all of these data frames with the value that is equal to a character in the dataframe names?
The expected output is something like
dataframe (1.3.A)
Person Height Weight Trial Day Group
Alex 175 75 1 3 A
Gerard 180 85 1 3 A
Clyde 179 79 1 3 A
dataframe (2.2.A)
Person Height Weight Trial Day Group
Missy 175 75 2 2 A
Britany 180 85 2 2 A
Sussie 179 79 2 2 A
dataframe (1.1.B)
Person Height Weight Trial Day Group
Luke 175 75 1 1 B
Alex 180 85 1 1 B
Haley 179 79 1 1 B
currently, all dataframes have the column 'Person' 'Height' and 'Weight' and I want to add the columns 'Trial' 'Day' and 'Group'.
I hope someone could help me with this. Sorry, I'm just a beginner in R.
I was thinking of maybe using ifelse() and names() then map() it to the entire dataframe list but could not figure out how. thanks