I am trying to create a new variable (incomeX) in a data frame based on the last character of the colnames so if:
income1 income2 income3 income4 income5
1 0 1 0 0 0
2 1 0 0 0 0
3 1 0 0 0 0
4 1 0 0 0 0
5 1 0 0 0 0
6 1 0 0 0 0
7 0 1 0 0 0
8 1 0 0 0 0
9 1 0 0 0 0
10 0 0 0 1 0
I would get:
income1 income2 income3 income4 income5 incomeX
1 0 1 0 0 0 2
2 1 0 0 0 0 1
3 1 0 0 0 0 1
4 1 0 0 0 0 1
5 1 0 0 0 0 1
6 1 0 0 0 0 1
7 0 1 0 0 0 2
8 1 0 0 0 0 1
9 1 0 0 0 0 1
10 0 0 0 1 0 4