Re: [R] Summarizing elements of a list
Thank you for the help, I knew it could be done with a member of the apply family. I struggle with apply stuff though, its not always intuitive for me with these functions. Cheers, JR From: Sarah Goslee [via R] [mailto:ml-node+s789695n414453...@n4.nabble.com] Sent: Thursday, December 01, 2011 6:44 PM To: ROLL Josh F Subject: Re: Summarizing elements of a list How about: lapply(Version1_, subset, subset=c(TRUE, FALSE)) or sapply() depending on what you want the result to look like. Thanks for the reproducible example. Sarah On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 [hidden email]/user/SendEmail.jtp?type=nodenode=4144538i=0 wrote: Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_-list() for(i in 1:5){ Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- Sarah Goslee http://www.functionaldiversity.org __ [hidden email]/user/SendEmail.jtp?type=nodenode=4144538i=1 mailing list 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4144538.html To unsubscribe from Summarizing elements of a list, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4142479code=anJvbGxAbGNvZy5vcmd8NDE0MjQ3OXwtMTcwMzUwNjI0Mg==. NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4148568.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Summarizing elements of a list
Great, this worked the fastest of all the suggestions. Cheers, Josh From: Michael Weylandt [via R] [mailto:ml-node+s789695n414494...@n4.nabble.com] Sent: Thursday, December 01, 2011 8:11 PM To: ROLL Josh F Subject: Re: Summarizing elements of a list Similarly, this might work: unlist(lapply(Version1_, `[`,First)) Michael On Thu, Dec 1, 2011 at 9:41 PM, Sarah Goslee [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=0 wrote: How about: lapply(Version1_, subset, subset=c(TRUE, FALSE)) or sapply() depending on what you want the result to look like. Thanks for the reproducible example. Sarah On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=1 wrote: Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_-list() for(i in 1:5){ Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- Sarah Goslee http://www.functionaldiversity.org __ [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=2 mailing list 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. __ [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=3 mailing list 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4144941.html To unsubscribe from Summarizing elements of a list, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4142479code=anJvbGxAbGNvZy5vcmd8NDE0MjQ3OXwtMTcwMzUwNjI0Mg==. NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4148571.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Summarizing elements of a list
Here's a slight modification that is even faster if speed is a consideration: sapply(Version1_, `[[`, First) The thought process is to go through the list Version1_ and apply the operation `[[` to each element individually. This requires a second operator (here the element name First) which we pass through the ... of sapply() -- I hope that helps you get a sense of the mechanics. We use sapply() instead of lapply() because it does some internal simplification for us to get one big vector back, effectively cutting out the unlist of the first solution I gave you. Michael On Fri, Dec 2, 2011 at 2:04 PM, LCOG1 jr...@lcog.org wrote: Great, this worked the fastest of all the suggestions. Cheers, Josh From: Michael Weylandt [via R] [mailto:ml-node+s789695n414494...@n4.nabble.com] Sent: Thursday, December 01, 2011 8:11 PM To: ROLL Josh F Subject: Re: Summarizing elements of a list Similarly, this might work: unlist(lapply(Version1_, `[`,First)) Michael On Thu, Dec 1, 2011 at 9:41 PM, Sarah Goslee [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=0 wrote: How about: lapply(Version1_, subset, subset=c(TRUE, FALSE)) or sapply() depending on what you want the result to look like. Thanks for the reproducible example. Sarah On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=1 wrote: Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_-list() for(i in 1:5){ Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- Sarah Goslee http://www.functionaldiversity.org __ [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=2 mailing list 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. __ [hidden email]/user/SendEmail.jtp?type=nodenode=4144941i=3 mailing list 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4144941.html To unsubscribe from Summarizing elements of a list, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4142479code=anJvbGxAbGNvZy5vcmd8NDE0MjQ3OXwtMTcwMzUwNjI0Mg==. NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4148571.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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@r-project.org mailing list 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.
Re: [R] Summarizing elements of a list
Someone is bound to know a better way, but... subset(unlist(Version1_), subset=names(unlist(Version1_))==First) LCOG1 wrote Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_-list() for(i in 1:5){ Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4142884.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Summarizing elements of a list
How about: lapply(Version1_, subset, subset=c(TRUE, FALSE)) or sapply() depending on what you want the result to look like. Thanks for the reproducible example. Sarah On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 jr...@lcog.org wrote: Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_-list() for(i in 1:5){ Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list 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.
Re: [R] Summarizing elements of a list
Similarly, this might work: unlist(lapply(Version1_, `[`,First)) Michael On Thu, Dec 1, 2011 at 9:41 PM, Sarah Goslee sarah.gos...@gmail.com wrote: How about: lapply(Version1_, subset, subset=c(TRUE, FALSE)) or sapply() depending on what you want the result to look like. Thanks for the reproducible example. Sarah On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 jr...@lcog.org wrote: Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_-list() for(i in 1:5){ Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list 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@r-project.org mailing list 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.