My article on computing on the language was unexpectedly popular and so I wanted to quickly follow up on my own solution. Many of you got the answer, and in fact many got solutions that were quite a bit shorter than mine. Here’s how I did it:
Baptiste pointed out that Frank Harrell has already implemented this function in his Hmisc package as the ‘llist’ function (thanks for the pointer!). I’ll just note that this function does a bit more actually because each element of the returned list is an object of class “labelled”.
The shortest solution was probably Tony Breyal’s version:
However, it’s worth noting that this function modifies the object’s name if the name is non-standard (i.e. if you’re using backticks like `r object name`). That’s just because the ‘data.frame’ function automatically modifies names if they are non-standard.
Thanks to everyone for the responses! I’ll try to come up with another one soon.