[R] Accessing selected elements of a list

2012-11-08 Thread Gonçalo Ferraz
Hi, If I have a vector: junk - c(2,0,0,3,0) and want to access, say, all the elements that are greater than zero. I just do: junk[which(junk0)] Now, If I have a list: jlist - list(NULL,c(1,0),NULL,c(1,2,3), NULL) and want to access all the elements that have length greater than zero, I

Re: [R] Accessing selected elements of a list

2012-11-08 Thread Rui Barradas
Hello, Just try jlist[ sapply(jlist,length) 0 ] Hope this helps, Rui Barradas Em 08-11-2012 14:42, Gonçalo Ferraz escreveu: Hi, If I have a vector: junk - c(2,0,0,3,0) and want to access, say, all the elements that are greater than zero. I just do: junk[which(junk0)] Now, If I have

Re: [R] Accessing selected elements of a list

2012-11-08 Thread jim holtman
try this (use '[' for indexing) jlist - list(NULL,c(1,0),NULL,c(1,2,3), NULL) jlist [[1]] NULL [[2]] [1] 1 0 [[3]] NULL [[4]] [1] 1 2 3 [[5]] NULL which(sapply(jlist, length) 0) [1] 2 4 jlist[sapply(jlist, length) 0] [[1]] [1] 1 0 [[2]] [1] 1 2 3 On Thu, Nov 8, 2012 at 9:42 AM,

Re: [R] Accessing selected elements of a list

2012-11-08 Thread arun
: [R] Accessing selected elements of a list Hi, If I have a vector: junk - c(2,0,0,3,0) and want to access, say, all the elements that are greater than zero. I just do: junk[which(junk0)] Now, If I have a list: jlist - list(NULL,c(1,0),NULL,c(1,2,3), NULL) and want to access all

Re: [R] Accessing selected elements of a list

2012-11-08 Thread arun
#[[5]] #NULL A.K. - Original Message - From: Gonçalo Ferraz gferra...@gmail.com To: r-help@r-project.org Cc: Sent: Thursday, November 8, 2012 9:42 AM Subject: [R] Accessing selected elements of a list Hi, If I have a vector: junk - c(2,0,0,3,0) and want to access, say, all

[R] Accessing matrix elements within a list

2010-06-26 Thread Maria P Petrova
Hi there, I cannot seem to figure out how to access the elements of a list if those elements are a matrix. For example I have a the following list df.list - vector(list, 3) and I have made each of the elements a matrix as follows for(i in 1:3){ assign(paste(s,i, sep=),matrix(0, nrow = 20,

Re: [R] Accessing matrix elements within a list

2010-06-26 Thread jim holtman
first of all take a look at the object you created: df.list - vector(list, 3) for(i in 1:3){ + assign(paste(s,i, sep=),matrix(0, nrow = 20, ncol = 5, byrow + = FALSE, dimnames = NULL)) + } # and then insert them with a loop like this # put matrices names in a vector matrices-c(s1,s2,s3)

[R] Accessing the elements of a list

2008-02-01 Thread Shubha Vishwanath Karanth
Hi R, I wanted to know how do we access the elements of a list. In particular, v=list(c(1,2,3,4,5),c(1,2,33,4,5),c(1,2,333,4,5),c(1,2,,4,5)) I want to access all the thirds items of the elements of the list. i.e., I want to access the elements, 3,33,333,. This can be done

Re: [R] Accessing the elements of a list

2008-02-01 Thread Bill.Venables
can't use sapply before we can really help you, though. Bill Venables. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Friday, 1 February 2008 7:05 PM To: [EMAIL PROTECTED] Subject: [R] Accessing the elements of a list Hi

Re: [R] Accessing the elements of a list

2008-02-01 Thread Thibaut Jombart
Shubha Vishwanath Karanth wrote: Hi R, I wanted to know how do we access the elements of a list. In particular, v=list(c(1,2,3,4,5),c(1,2,33,4,5),c(1,2,333,4,5),c(1,2,,4,5)) I want to access all the thirds items of the elements of the list. i.e., I want to access the