

In R I have a dataframe like below. So if the string in column LOC is same for the record id then move the information from 2nd row to columns in the 1st row.

mydata
ID LOC LOC_a LOC_b LOC_2a LOC_2b
1 LAX 1 2
1 LAX 3 4
1 NJ 1 2
2 LAX 1 2
3 NJ 1 2
4 DM 5 6
4 DM 7 8

Desired output
ID LOC LOC_a LOC_b LOC_2a LOC_2b
1 LAX 1 2 3 4
1 NJ 1 2 
2 LAX 1 2
3 NJ 1 2
4 DM 5 6 7 8

    r

 Your response should contain less than 300 words.
user