# Technical name for this data wrangling process? Multiple columns into multi-factor single column

What is the technical name for the following data wrangling process? I want to collapse Table A into Table B. (To make the data suitable for ANOVA.)

Table A:

ArmyVet_ID  Served_WW2  Served_KoreanWar    Served_VietnamWar
110001          1              0                    0
110002          1              0                    0
110004          0              1                    0
110005          0              1                    0
110009          0              0                    1
110010          0              0                    1


Table B:

ArmyVet_ID    Served
110001          WW2
110002          WW2
110004          KoreanWar
110005          KoreanWar
110009          VietnamWar
110010          VietnamWar


Also, the question of how to do the above conversion using R has been asked to death on SO. However, there seem to be way too many ways to do it. If anyone's figured out the absolutely best way to do it (quickest, easiest), I'd appreciate pointers.

Update after correct answer marked below: It turns out that Table A is called "wide format" and B is called "long format".

• The answer given is right, but 'wide format to long format' might be even more specific, also, I recommend reshape2 instead of reshape, reshape is, as I understand it, underdocumented Jun 8 '16 at 22:42
• @Shape Do you know of any more synonyms of "reshape"? It shocks me that when I look for 'reshape' and Weka or Rapidminer I get nothing on google. Jun 9 '16 at 6:08
• It's "normalization" in database theory. Jun 9 '16 at 8:55

It is usually called reshaping! For a great description of the process, see this walkthrough, or read up on Hadley Wickham's documentation for the reshape package!

df['Served'] = (df.iloc[:, 1:] == 1).idxmax(1)

• Welcome to the site! I have submitted an edit for your answer so that it displays as properly formatted code with the markdown language. Mar 15 '19 at 17:52