Re: [R] Matrix from List

2008-07-25 Thread jim holtman
This gets you close to what you want. The 31/33 are row names that you can extract and store as actual columns, > x <- list('1995'=list('31'=1, '33'=2), '2006'=list('31'=3, '33'=4)) > y <- lapply(names(x), function(.L1){ + cbind(as.numeric(.L1),do.call(rbind, x[[.L1]])) + }) > (z <- do.call(r

[R] Matrix from List

2008-07-25 Thread Nelson Villoria
Hello, I have a list in which each element is a list. I want to create a matrix indexed by the two indices of the list. I have been using do.call, but I am not getting what I want. Let me show you: > l.intercepts #the list that nests another list $`1995` $`1995`$`31` (Intercept) 25.37164 $`199

Re: [R] matrix from list

2008-04-28 Thread Prof Brian Ripley
e it is not obvious what to return without giving extra information, it is better to require the extra information through other functions. From: [EMAIL PROTECTED] on behalf of Olivier Lefevre Sent: Sat 4/26/2008 9:43 AM To: [EMAIL PROTECTED] Subject: Re: [R] m

Re: [R] matrix from list

2008-04-28 Thread Kenn Konstabel
__ > > From: [EMAIL PROTECTED] on behalf of Olivier Lefevre > Sent: Sat 4/26/2008 9:43 AM > To: [EMAIL PROTECTED] > Subject: Re: [R] matrix from list > > > > Olivier Lefevre wrote: > > Anyway you are right that it would still return the kind of object, only > >

Re: [R] matrix from list

2008-04-27 Thread Olivier Lefevre
It's true one may have to set some rules but I think you are blowing it up. First, it is true one would have to agree for list[[vec]] to always return a matrix but it is the useful behaviour since you can already get a vector with unlist(list[vec]). Second, as to the raggedness, matrix(), array

Re: [R] matrix from list

2008-04-26 Thread Greg Snow
her functions. From: [EMAIL PROTECTED] on behalf of Olivier Lefevre Sent: Sat 4/26/2008 9:43 AM To: [EMAIL PROTECTED] Subject: Re: [R] matrix from list Olivier Lefevre wrote: > Anyway you are right that it would still return the kind of object, only > subs

Re: [R] matrix from list

2008-04-26 Thread Olivier Lefevre
Martin Maechler wrote: > The difference to as.matrix() is that data.matrix() also > produces a numeric matrix in the case the data frame contains > factors. Thanks, that is useful but it is becoming a little rococo: so may ways to do this. Also, what if I have a list, not a data frame? read

Re: [R] matrix from list

2008-04-26 Thread Olivier Lefevre
Olivier Lefevre wrote: > Anyway you are right that it would still return the kind of object, only > subsetted, which is not I want. I mean [] would do that; I know [[]] doesn't. Yet I still don't see why one accepts vector arguments but not the other: they are both indexing operators. It is suc

Re: [R] matrix from list

2008-04-26 Thread Martin Maechler
> "OL" == Olivier Lefevre <[EMAIL PROTECTED]> > on Sat, 26 Apr 2008 01:31:16 +0200 writes: OL> Greg Snow wrote: >> The '[[' only returns a single element from a data structure OL> I know but that is precisely what I find arbitrary. OL> Anyway you are right that it wou

Re: [R] matrix from list

2008-04-25 Thread Olivier Lefevre
Greg Snow wrote: > The '[[' only returns a single element from a data structure I know but that is precisely what I find arbitrary. Anyway you are right that it would still return the kind of object, only subsetted, which is not I want. As someone kindly pointed out to me offline, besides the u

Re: [R] matrix from list

2008-04-25 Thread Greg Snow
lthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Olivier Lefevre > Sent: Thursday, April 24, 2008 4:16 PM > To: [EMAIL PROTECTED] > Subject: Re: [R] matrix from list > > Yes, unlist is

Re: [R] matrix from list

2008-04-24 Thread Olivier Lefevre
Yes, unlist is the magic wand I was looking for. Thanks a million! Having said that, I find it rather arbitrary that you can write mat[1:4] but not list[[1:2]]; IMO there should be no need for a "magic" operator like unlist: list[[1:length(list)]] could do the job. -- O.L.

Re: [R] matrix from list

2008-04-24 Thread Jorge Ivan Velez
Hi Olivier, is this what you want? x="col1 col2 1 0.1 1.1 2 0.2 1.2" m=read.table(textConnection(x),header=TRUE) m1=matrix(unlist(m),ncol=2) m1 [,1] [,2] [1,] 0.1 1.1 [2,] 0.2 1.2 HTH, Jorge On Thu, Apr 24, 2008 at 6:02 PM, Olivier Lefevre <[EMAIL PROTECTED]> wrote: > Another possibly

[R] matrix from list

2008-04-24 Thread Olivier Lefevre
Another possibly simple thing that I cannot get right is how to extract the data part of a list as a matrix. The data were read from xls, with labels, and thus are of list mode, e.g., col1 col2 1 0.1 1.1 2 0.2 1.2 I want to extract from that just the numeric data part, i.e., (in this case