Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread William Dunlap via R-help
If you need to make a list of long but unknown length you can save time by adding the items to an environment, with names giving the order, then converting the environment to a list when you are done filling the environment. E.g., > makeData function (container, n) { for (i in seq_len(n)) con

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Dear Jeff, it is a precious help and a fabulous suggestion. I will slowly go over the R code that you have sent. Thanks a lot ! On Wed, Jul 25, 2018 at 10:43 AM, Jeff Newmiller wrote: > The code below reeks of a misconception that lists are efficient to add > items to, which is a confusion with

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Jeff Newmiller
The code below reeks of a misconception that lists are efficient to add items to, which is a confusion with the computer science term "linked list". In R, a list is NOT a linked list... it is a vector, which means the memory used by the list is allocated at the time it is created, and REALLOCA

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Dear Thierry and Juan, thank you for your help. Thank you all. Now, if I would like to add an element to the empty list, how shall I do : for example, shall i = 2, and j = 1, in a bit of more complex R code : x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"), CHRA=c("chr1", "chr1",

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Huzefa Khalil
Hi Bogdan, Does the following do what you expect? x$intersectA[[i]] <- c(x$intersectA[[i]], x$labA[j]) Note the difference between `[[` and `[` On Wed, Jul 25, 2018 at 9:26 AM, Bogdan Tanasa wrote: > Dear Thierry and Juan, thank you for your help. Thank you very much. > > Now, if I would like

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Dear Thierry and Juan, thank you for your help. Thank you very much. Now, if I would like to add an element to the empty list, how shall I do : for example, shall i = 2, and j = 1, in a bit of more complex R code : x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"), CHRA=c("chr1", "

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Thank you Juan. On Wed, Jul 25, 2018 at 12:56 AM, Juan Telleria Ruiz de Aguirre < jtelleria.rproj...@gmail.com> 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 >

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Dénes Tóth
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 at

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Ivan Calandra
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

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Juan Telleria Ruiz de Aguirre
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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Juan Telleria Ruiz de Aguirre
> 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(). __ R-help@r-project.

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Ivan Calandra
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

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Thierry Onkelinx
Dear Bogdan, You are looking for x$intersectA <- vector("list", nrow(x)) Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / T

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Juan Telleria Ruiz de Aguirre
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

[R] initiate elements in a dataframe with lists

2018-07-24 Thread Bogdan Tanasa
Dear all, assuming that I do have a dataframe like : x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"), CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"), POSA=c(10, 15, 120, 340, 100, 220), CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"), POSB=c(30, 100, 300, 20, 200,