Re: [R] alternative to matching/merge?

From: Lana Schaffer <schaffer_at_scripps.edu>
Date: Tue, 17 Jun 2008 09:47:48 -0700

Jim,
I understand that that do.call will combine all the lists into a matrix. But I have a list,x, which is a list of a list as in x[[1]] and x[[2]] which are themselves lists. Then using
do.call(rbind, x)
would combine both x[[1]] and x[[2]] into a matrix. I want to keep x[[1]] and x[[2]] separately into their own matrix, and so I am putting do.call into a loop ie. do.call(rbind,x[[i]]) to keep them separate.
More elegantly I would want to put do.call into lapply but have not been successful to do this. Lana

-----Original Message-----
From: jim holtman [mailto:jholtman_at_gmail.com] Sent: Monday, June 16, 2008 5:24 PM
To: Lana Schaffer
Cc: hadley wickham; r-help_at_r-project.org Subject: Re: [R] alternative to matching/merge?

Is this what you tried:

> x <- data.frame(a=1:10, b=1:10)
> x <- data.frame(a=1:3, b=1:3)
> do.call(rbind, list(x,x,x,x,x))

   a b
1 1 1
2 2 2
3 3 3
4 1 1
5 2 2
6 3 3
7 1 1
8 2 2
9 3 3
10 1 1
11 2 2
12 3 3
13 1 1
14 2 2
15 3 3
>

On Mon, Jun 16, 2008 at 7:36 PM, Lana Schaffer <schaffer_at_scripps.edu> wrote:
> Jim,
> Is it possible to do a do.call(rbind,d.frame) with a list like using
> lapply(data,func,args)?
> I have not successfully executed this.
> Lana
>
> -----Original Message-----
> From: hadley wickham [mailto:h.wickham_at_gmail.com]
> Sent: Friday, June 13, 2008 2:54 PM
> To: jim holtman
> Cc: Lana Schaffer; r-help_at_r-project.org
> Subject: Re: [R] alternative to matching/merge?
>
> On Fri, Jun 13, 2008 at 11:45 AM, jim holtman <jholtman_at_gmail.com>
> wrote:
>> What is the structure of 'd.frame' and 'segFile'? Run Rprof so that
>> we can see which of the functions it is spending its time in. What
>> happens if x$index is not in seqFile$index? Are the values in the
>> 'index' unique in both structures? Subsetting a data frame can be
>> expensive when compared to using a matrix. Could you use a matrix
>> instead of a data frame; are all the columns the same mode? Again
>> either a subset of data would be helpful or an 'str' on the data
>> objects being used so that we can understand what they are.
>
> A few other ideas to try:
>
> * try merging do.call("rbind", d.frame) and seqFile, and then
> spliting the results back up
>
> * try turning giving seqFile rownames (rownames(seqFile) <-
> seqFile$index) and then use character matching: cbind(x, seqFile[
> as.character(x$index)]
>
> * if there is a one to one corresponding between index in seqFile and

> all data.frames in d.frame, merge all of the d.frames together, order
> both by index then just cbind
>
> Hadley
>
>
> --
> http://had.co.nz/
>

--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_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.
Received on Tue 17 Jun 2008 - 17:04:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 Jun 2008 - 17:30:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive