I am trying to understand how "melting" works in complex situations. I've seen plenty of posts and blogs about using these packages in very simple cases - but not in more difficult ones. For example:
Lets say I have the following data in a dataframe:
CA UNIT SCP DATE1 TIME1 DESC1 ENTRIES1 EXITS1
1 A002 R051 02-00-00 07-27-13 00:00:00 REGULAR 4209603 1443585
2 A002 R051 02-00-00 07-28-13 08:00:00 REGULAR 4210490 1443821
3 A002 R051 02-00-00 07-29-13 16:00:00 REGULAR 4211586 1444302
4 A002 R051 02-00-00 07-30-13 14:01:46 LOGON 4213192 1444700
5 A002 R051 02-00-00 07-30-13 16:00:00 REGULAR 4213333 1444737
6 A002 R051 02-00-00 08-01-13 00:00:00 REGULAR 4215894 1445274`
and continued columns to the right (sorry, I couldn't format it properly in the code block):
`DATE2 TIME2 DESC2 ENTRIES2 EXITS2
1 07-27-13 08:00:00 REGULAR 4209663 1443616
2 07-28-13 16:00:00 REGULAR 4210775 1443921
3 07-30-13 00:00:00 REGULAR 4212845 1444369
4 07-30-13 14:02:18 DOOR OPEN 4213192 1444700
5 07-31-13 00:00:00 REGULAR 4214345 1444823
6 08-01-13 08:00:00 REGULAR 4215977 1445362`
and I want to melt this into a dataframe with the following format:
CA UNIT SCP DATE TIME DESC ENTRIES EXITS
1 A002 R051 02-00-00 07-27-13 00:00:00 REGULAR 4209603 1443585
2 A002 R051 02-00-00 07-28-13 08:00:00 REGULAR 4210490 1443821
3 A002 R051 02-00-00 07-29-13 16:00:00 REGULAR 4211586 1444302
4 A002 R051 02-00-00 07-30-13 14:01:46 LOGON 4213192 1444700
5 A002 R051 02-00-00 07-30-13 16:00:00 REGULAR 4213333 1444737
6 A002 R051 02-00-00 08-01-13 00:00:00 REGULAR 4215894 1445274
7 A002 R051 02-00-00 07-27-13 08:00:00 REGULAR 4209663 1443616
8 A002 R051 02-00-00 07-28-13 16:00:00 REGULAR 4210775 1443921
9 A002 R051 02-00-00 07-30-13 00:00:00 REGULAR 4212845 1444369
10A002 R051 02-00-00 07-30-13 14:02:18 DOOR OPEN 4213192 1444700
11A002 R051 02-00-00 07-31-13 00:00:00 REGULAR 4214345 1444823
12A002 R051 02-00-00 08-01-13 08:00:00 REGULAR 4215977 1445362
The challenge here is that the columns I want to "melt" have different data types. All the posts I read are very straightforward and assume all the melted columns are of the same data type and will fall into nice key/value pairs. That is clearly not the case here.
I have found another post that indicates this restructuring can be done using the 'replace' from stats. I get that. But if dplyr, reshape2, and tidyr can't be used for more complicated real world scenarios what is the real use?
Please show how to do this with tidyr, dplyr or reshape2.
Thank you in advance!