[R] initiate elements in a dataframe with lists

Dénes Tóth toth@dene@ @end|ng |rom kogentum@hu
Wed Jul 25 12:41:57 CEST 2018



On 07/25/2018 10:23 AM, Ivan Calandra wrote:
> Just for my understanding:
> Is a data.frame with list columns still a data.frame? Isn't it then a list?

A data.frame is a list of equally sized vectors - that is, each vector 
must be of the same length. It is not required that the vector is an 
atomic vector; it can be a list, too. By having equally sized vectors in 
a list you can arrange the list in a two-dimensional matrix-like format, 
append row names to them, and you get a data.frame.

Principally data.frame(x = 1:3, y = list(1:2, 1:3, 1:4)) should work, 
but it doesn't, as it was recognized by others, too:
https://stackoverflow.com/questions/9547518/create-a-data-frame-where-a-column-is-a-list

Cheers,
Denes


> 
> Ivan
> 
> -- 
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
> 
> On 25/07/2018 09:56, Juan Telleria Ruiz de Aguirre wrote:
>> Check tidyverse's purrr package:
>>
>> https://github.com/rstudio/cheatsheets/raw/master/purrr.pdf
>>
>> In the second page of the cheatsheet there is info on how to create list
>> columns within a data.frame :)
>>
>>     [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list