[R] why data.frame, mutate package and not lists

Marc Schwartz marc_schwartz at me.com
Wed Sep 14 17:30:42 CEST 2016


> On Sep 14, 2016, at 8:01 AM, Alaios via R-help <r-help at r-project.org> wrote:
> 
> Hi all,I have seen data.frames and operations from the mutate package getting really popular. In the last years I have been using extensively lists, is there any reason to not use lists and use other data types for data manipulation and storage?
> Any article that describe their differences? I would like to thank you for your replyRegardsAlex

Hi,

Presuming that you are referring to the mutate() **function**, which is in the dplyr package on CRAN, that package provides a variety of functions to manipulate data in R.

Data frames **are** lists with a data.frame class attribute, but with the proviso that each column in the data frame, which is a list element, has the same length, but like a list, may have different data types (e.g. character, numeric, etc.). 

Thus, a data frame is effectively a rectangular data structure, conceptually in the same manner as an Excel worksheet.

A list, which is a more generic data structure, can contain list elements of variable lengths and data types. 

You might want to begin by reviewing:

  https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Lists-and-data-frames

which is a section on lists and data frames in the Introduction To R Manual.

It would be surprising, to me at least, that you have been using R for several years and have not come across data frames, since they are used in many typical operations, including regression models and the like.

Regards,

Marc Schwartz
 


More information about the R-help mailing list