structure()

Ten Data Analysis Tips in R: Answers to Webinar Questions

February 5th, 2013 by


We were recently fortunate to host a free The Craft of Statistical Analysis Webinar with guest presenter David Lillis.  As usual, we had hundreds of attendees and didn’t get through all the questions.  So David has graciously agreed to answer questions here.

If you missed the live webinar, you can download the recording here:  Ten Data Analysis Tips in R.

Q: Is the M=structure(.list(.., class = “data.frame) the same as M=data.frame(..)? Is there some reason to prefer to use structure(list, … ,) as opposed to M=data.frame?

A: They are not the same. The structure( .. .)  syntax is a short-hand way of storing a data set. If you have a data set called M, then the command dput(M) provides a shorthand way of storing the dataset. You can then reconstitute it later as follows: M <- structure( . . . .). Try it for yourselves on a rectangular dataset.  For example, start off with (more…)