Re: [R] subsetting a list of matrices

2006-02-28 Thread Marco Geraci
Hi. Have you tried 'help.search('list')' ? See ?lapply > lapply(z, function(s) s[2:3,,drop=F]) [[1]] [,1] [,2] [1,]25 [2,]36 [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 19 22 25 28 31 34 [2,] 20 23 26 29 32 35 Marco Geraci --- Federico Calboli <[E

Re: [R] subsetting a list of matrices

2006-02-28 Thread Marc Schwartz (via MN)
On Tue, 2006-02-28 at 17:14 +, Federico Calboli wrote: > Hi All, > > I have a list of matrices: > > > x > [,1] [,2] > [1,]14 > [2,]25 > [3,]36 > > y > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 18 21 24 27 30 33 > [2,] 19 22 25 28 31 34 > [3

Re: [R] subsetting a list of matrices

2006-02-28 Thread Sundar Dorai-Raj
Federico Calboli wrote: > Hi All, > > I have a list of matrices: > > >>x > > [,1] [,2] > [1,]14 > [2,]25 > [3,]36 > >>y > > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 18 21 24 27 30 33 > [2,] 19 22 25 28 31 34 > [3,] 20 23 26 29

Re: [R] subsetting a list of matrices

2006-02-28 Thread Gabor Grothendieck
Try this: lapply(z, "[", 2:3, TRUE) On 2/28/06, Federico Calboli <[EMAIL PROTECTED]> wrote: > Hi All, > > I have a list of matrices: > > > x > [,1] [,2] > [1,]14 > [2,]25 > [3,]36 > > y > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 18 21 24 27 30 33 > [2,] 1

[R] subsetting a list of matrices

2006-02-28 Thread Federico Calboli
Hi All, I have a list of matrices: > x [,1] [,2] [1,]14 [2,]25 [3,]36 > y [,1] [,2] [,3] [,4] [,5] [,6] [1,] 18 21 24 27 30 33 [2,] 19 22 25 28 31 34 [3,] 20 23 26 29 32 35 > z =list(x,y) I want to create a second list that is

Re: [R] Subsetting a list

2005-10-21 Thread Prof Brian Ripley
On Fri, 21 Oct 2005, Martin Maechler wrote: >> "PaCo" == Patrick Connolly <[EMAIL PROTECTED]> >> on Fri, 21 Oct 2005 13:26:08 +1300 writes: > >PaCo> On Wed, 19-Oct-2005 at 05:09PM +0200, Martin Maechler wrote: >PaCo> |> Lists can have 'dim' attributes and hence be treated as ar

Re: [R] Subsetting a list

2005-10-21 Thread Martin Maechler
> "PaCo" == Patrick Connolly <[EMAIL PROTECTED]> > on Fri, 21 Oct 2005 13:26:08 +1300 writes: PaCo> On Wed, 19-Oct-2005 at 05:09PM +0200, Martin Maechler wrote: PaCo> |> Lists can have 'dim' attributes and hence be treated as arrays; PaCo> |> Note that this is pretty rarely

Re: [R] Subsetting a list

2005-10-20 Thread Patrick Connolly
On Wed, 19-Oct-2005 at 05:09PM +0200, Martin Maechler wrote: |> Lists can have 'dim' attributes and hence be treated as arrays; |> Note that this is pretty rarely used and not too well supported |> by some tools, one could say even 'print()' : |> |> > set.seed(0); L0 <- L <- lapply(rpois(12, lam

Re: [R] Subsetting a list

2005-10-19 Thread Vincent Goulet
Le 19 Octobre 2005 11:09, Martin Maechler a écrit : [...] > Lists can have 'dim' attributes and hence be treated as arrays; For me, this is an amazing feature that I discovered almost by accident (I tried it an it worked)! This creates a sort of three-dimensional object --- much like an array

Re: [R] Subsetting a list

2005-10-19 Thread Martin Maechler
> "Jose" == José Ernesto Jardim <[EMAIL PROTECTED]> > on Tue, 18 Oct 2005 15:30:59 +0100 writes: Jose> Dennis Fisher wrote: >> Colleagues, >> >> I have created a list in the following manner: >> TEST<- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2")) >>

Re: [R] Subsetting a list

2005-10-19 Thread John Wilkinson \(pipex\)
Dennis Try > TEST[-3] [[1]] [1] "A1" "A2" [[2]] [1] "B1" "B2" for removing more than one element from the list (say 2 & 3) -- > TEST[-c(2,3)] [[1]] [1] "A1" "A2" HTH John Dennis Fisher wrote--- Colleagues, I have created a list in the following manner: TEST<- list(c("A1",

Re: [R] Subsetting a list

2005-10-18 Thread Arturo Coral Alamo
Hi, you can use this: TEST[[3]]<-NULL > TEST [[1]] [1] "A1" "A2" [[2]] [1] "B1" "B2" Saludos Jaime Arturo Coral student PUCP - PERU On 10/18/05, Dennis Fisher <[EMAIL PROTECTED]> wrote: > > Colleagues, > > I have created a list in the following manner: > TEST <- list(c("A1", "A2"), c("B1",

Re: [R] Subsetting a list

2005-10-18 Thread Dimitris Rizopoulos
tholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "Dennis Fisher" <[EMAIL PROTECTED]&

Re: [R] Subsetting a list

2005-10-18 Thread ernesto
Dennis Fisher wrote: >Colleagues, > >I have created a list in the following manner: > TEST<- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2")) > >I now want to delete one element from the list, e.g., the third. The >command > TEST[[3]] >yields (as expected): > [1] "C1" "C2" > >T

Re: [R] Subsetting a list

2005-10-18 Thread Huntsinger, Reid
You have to use "[" instead of "[[" to return a sub-list. Reid Huntsinger -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dennis Fisher Sent: Tuesday, October 18, 2005 10:12 AM To: r-help@stat.math.ethz.ch Subject: [R] Subsetting a l

Re: [R] Subsetting a list

2005-10-18 Thread Duncan Murdoch
On 10/18/2005 10:11 AM, Dennis Fisher wrote: > Colleagues, > > I have created a list in the following manner: > TEST<- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2")) > > I now want to delete one element from the list, e.g., the third. The > command > TEST[[3]] > yields (as exp

[R] Subsetting a list

2005-10-18 Thread Dennis Fisher
Colleagues, I have created a list in the following manner: TEST<- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2")) I now want to delete one element from the list, e.g., the third. The command TEST[[3]] yields (as expected): [1] "C1" "C2" The command TEST[[-3]] yields:

Re: [R] Subsetting a list of vectors

2003-11-14 Thread Gabor Grothendieck
0)x^2 else NA, rm=NA ) --- Date: Mon, 10 Nov 2003 00:23:17 -0500 (EST) From: Gabor Grothendieck <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Subject: Re: [R] Subsetting a list of vectors

Re: [R] Subsetting a list of vectors

2003-11-10 Thread Hadley Wickham
Thanks to you all for your helpful solutions. I particularly like the simplicity of Gabor's na.omit( sapply(... ) ) formulation, but you've all given me some ideas to think about. Thanks again, Hadley __ [EMAIL PROTECTED] mailing list https://www.s

Re: [R] Subsetting a list of vectors

2003-11-10 Thread Eric Lecoutre
Hi, I propose here a solution that relies on names of elements: # From a list, with any names ll=list(v1=1:4,v2=1:2,v3=5:7,v4=9:11,v5=1,v6=rnorm(4)) # Make a copy to be able to change names ll2=ll names(ll2)=rep("a",lengh(ll2)) # Use unlist, which "autobuilds" names based on # previous names and

Re: [R] Subsetting a list of vectors

2003-11-09 Thread Gabor Grothendieck
Dirk and Ray have provided two very clever solutions which perform transformation and selection in one go by returning NA and NULL respectively for unwanted elements and then eliminating the NAs and NULLs. I thought it would be worthwhile to bring them together and make some further minor

Re: [R] Subsetting a list of vectors

2003-11-09 Thread Dirk Eddelbuettel
On Sun, Nov 09, 2003 at 09:29:26PM -0600, Dirk Eddelbuettel wrote: > On Sun, Nov 09, 2003 at 10:00:42PM -0500, Gabor Grothendieck wrote: > > There are languages that do allow this. For example, Python > > has list comprehensions which are things like this: > > > ># give me the squares of the

Re: [R] Subsetting a list of vectors

2003-11-09 Thread Dirk Eddelbuettel
On Sun, Nov 09, 2003 at 10:00:42PM -0500, Gabor Grothendieck wrote: > There are languages that do allow this. For example, Python > has list comprehensions which are things like this: > ># give me the squares of the even numbers from 1-10, in a list. >>>> [ x*x for x in range(1,11) if x

RE: [R] Subsetting a list of vectors

2003-11-09 Thread Gabor Grothendieck
xpression in the terms we want.) --- Date: Mon, 10 Nov 2003 13:43:07 +1300 From: Hadley Wickham <[EMAIL PROTECTED]> To: R-Help Mailing List <[EMAIL PROTECTED]> Subject: [R] Subsetting a list of vectors Hi, I'm trying to subset a list which contains variable length vectors.

Re: [R] Subsetting a list of vectors

2003-11-09 Thread Spencer Graves
When I did it in S-Plus 6.1 and R 1.8.0, I didn't get NULL entries: I got NAs. There is a difference between NULLs and NAs. The NAs can be deleted using is.na, as follows: > list.of.vectors <- list(a=1, b=1:3) > x3 <- sapply(list.of.vectors, function(x)x[3]) > x3 a b NA 3 > x3 a b NA 3 >

[R] Subsetting a list of vectors

2003-11-09 Thread Hadley Wickham
Hi, I'm trying to subset a list which contains variable length vectors. What I want to do is extract (eg.) the 3rd item in each vector (with length >= 3). At the moment I'm using sapply(list.of.vectors, function(x) {x[3]}). The problem with this is that sapply returns a list of the same len