I had a very long file of monetary transactions (about 207,000 rows) with about two handfuls of columns describing each transaction (including date). The task I needed to perform on this file was to select the value from one of the categorical descriptor columns (called “appeal”) associated with the first transaction found for every ID in the file. Luckily for me, the file was organized so that the older transactions came before the newer transactions. The coding solution I used was pretty simple, but took maybe 5 – 10 minutes to complete.
Assuming the data frame is called ‘trans.file’, the numerical ID is called, ‘Num.ID’, and the categorical descriptor column of interest is called ‘appeal’, here’s the simple code:
first.appeal.by.id = ddply(trans.file, “Num.ID”, function (x) as.character(x$appeal))
I do like simple, but I also like fast. Is there a less computationally expensive way of doing this? Please tell me if so 🙂