I have a list of 25 data table, each table has 2 columns. The tables inside the list are named from 1 to 25. I would like to add a column in each table containing in each row just the name of the table, like this:
Table 1
A B
x y
x y
x y
Table 2
A B
x y
x y
x y
Table 3
A B
x y
x y
x y
Table 1 new
| A | B | new column |
|---|---|---|
| X | Y | 1 |
| X | Y | 1 |
| X | Y | 1 |
Table 2 new
| A | B | new column |
|---|---|---|
| X | Y | 2 |
| X | Y | 2 |
| X | Y | 2 |
Table 3 new
| A | B | new column |
|---|---|---|
| X | Y | 3 |
| X | Y | 3 |
| X | Y | 3 |
I know I should use function(x) and then lapply, and I know there are different ways to add a new column. I just don't know how to fill the columns with the numbers.