[R] indexing lists

2010-11-15 Thread Chris Carleton
Hi List, I'm trying to work out how to use which(), or another function, to find the top-level index of a list item based on a condition. An example will clarify my question. a - list(c(1,2),c(3,4)) a [[1]] [1] 1 2 [[2]] [1] 3 4 I want to find the top level index of c(1,2), which should return

Re: [R] indexing lists

2010-11-15 Thread Erik Iverson
Chris, Well, the 'answer' could be: which(sapply(a, function(x) all(x == c(1,2 But I wonder how these elements of 'a' in your actual application are coming to be? If you're constructing them, you can give the elements of the list names, and then it doesn't matter what numerical index they

Re: [R] indexing lists

2010-11-15 Thread Joshua Wiley
Hi Chris, Does this do what you're after? It just compares each element of a (i.e., a[[1]] and a[[2]]) to c(1, 2) and determines if they are identical or not. which(sapply(a, identical, y = c(1, 2))) There were too many 1s floating around for me to figure out if you wanted to find elements of

Re: [R] indexing lists

2010-11-15 Thread David Winsemius
On Nov 15, 2010, at 4:24 PM, Chris Carleton wrote: Hi List, I'm trying to work out how to use which(), or another function, to find the top-level index of a list item based on a condition. An example will clarify my question. a - list(c(1,2),c(3,4)) a [[1]] [1] 1 2 [[2]] [1] 3 4 I

Re: [R] indexing lists

2010-11-15 Thread Chris Carleton
Thanks for the suggestions. The issue for me is that the top level index is also like a database key so it might be a bit annoying to coerce it to char() so that I can reference it with a $ and then I would have to still be able to find out what the name was automatically. I've got a function

Re: [R] indexing lists

2010-11-15 Thread David Winsemius
On Nov 15, 2010, at 5:07 PM, Chris Carleton wrote: Thanks for the suggestions. The issue for me is that the top level index is also like a database key so it might be a bit annoying to coerce it to char() so that I can reference it with a $ and then I would have to still be able to find

Re: [R] indexing lists

2010-11-15 Thread Chris Carleton
Thanks for the suggestions, but 'cat' is not causing name space conflicts for me and since I'm not packaging the code for anyone else to use, I'm less than concerned about potential conflicts. I did type that too quickly, and I have resolved my problem using a workaround that does not involve

Re: [R] indexing lists

2010-11-15 Thread David Winsemius
On Nov 15, 2010, at 7:58 PM, Chris Carleton wrote: Thanks for the suggestions, but 'cat' is not causing name space conflicts for me install.packages( library(fortunes) fortune(dog) and since I'm not packaging the code for anyone else to use, I'm less than concerned about potential

[R] indexing lists, using brobdingnagian

2008-05-27 Thread Redding, Matthew
Dear R-Gurus, I have ended up with a calculation problem where I need to use brobs. I have to work my way through a vector with a for loop to act on each element in a calculation (refering to the previous value in the new vector of results -- so as far as I know I can't use apply) -- this

Re: [R] indexing lists, using brobdingnagian

2008-05-27 Thread Redding, Matthew
. Matt Redding -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Redding, Matthew Sent: Wednesday, 28 May 2008 10:18 AM To: r-help@r-project.org Subject: [R] indexing lists, using brobdingnagian Dear R-Gurus, I have ended up with a calculation problem