Just for my understanding: Is a data.frame with list columns still a data.frame? Isn't it then a list? 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 at 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. >
Juan Telleria Ruiz de Aguirre
2018-Jul-25 09:56 UTC
[R] initiate elements in a dataframe with lists
> Just for my understanding: > Is a data.frame with list columns still a data.frame? Isn't it then a list?* A data.frame (or tibble) is a list of columns. * In which each column must be from the same data type, in this case list().
Juan Telleria Ruiz de Aguirre
2018-Jul-25 09:58 UTC
[R] initiate elements in a dataframe with lists
By the way, this also works: dfl <- data.frame(x = 1:3, y = I(list(1:2, 1:3, 1:4))) As indicated in "Advanced R" book: http://adv-r.had.co.nz/Data-structures.html#data-frames
At first I was actually thinking about this situation, which cannot work:| data.frame(x = 1:3, y = list(1:2, 1:3, 1:4)) |But I had never thought about this:| df$y <-list(1:2, 1:3, 1:4)| And it actually makes sense. The final requirement here is that all columns must have the same length! I'm not sure though why one would need that. Why not use lists in that case? Thanks! 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 11:56, Juan Telleria Ruiz de Aguirre 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 (or tibble) is a list of columns. > * In which each column must be from the same data type, in this case list(). >[[alternative HTML version deleted]]
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 at 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 at 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. >