[R] merge

2008-10-03 Thread kayj

Hi All,

I want to merge file 2 into file 1 , is it possible to get the rows from
file 2 that did not end up in the merge result?

Thanks

-- 
View this message in context: 
http://www.nabble.com/merge-tp19805328p19805328.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] merge

2008-10-03 Thread stephen sefick
if you want to include all everything the add the argument all=TRUE
there is also a all.x and all.y which are explained in the
documentation.
hope this helps

On Fri, Oct 3, 2008 at 4:48 PM, kayj <[EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> I want to merge file 2 into file 1 , is it possible to get the rows from
> file 2 that did not end up in the merge result?
>
> Thanks
>
> --
> View this message in context: 
> http://www.nabble.com/merge-tp19805328p19805328.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>



-- 
Stephen Sefick
Research Scientist
Southeastern Natural Sciences Academy

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help@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.


Re: [R] merge

2008-10-03 Thread kayj


Thanks , but I want to find out the elements that were NOT merged from
file2?



stephen sefick wrote:
> 
> if you want to include all everything the add the argument all=TRUE
> there is also a all.x and all.y which are explained in the
> documentation.
> hope this helps
> 
> On Fri, Oct 3, 2008 at 4:48 PM, kayj <[EMAIL PROTECTED]> wrote:
>>
>> Hi All,
>>
>> I want to merge file 2 into file 1 , is it possible to get the rows from
>> file 2 that did not end up in the merge result?
>>
>> Thanks
>>
>> --
>> View this message in context:
>> http://www.nabble.com/merge-tp19805328p19805328.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@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.
>>
> 
> 
> 
> -- 
> Stephen Sefick
> Research Scientist
> Southeastern Natural Sciences Academy
> 
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
> 
>   -K. Mullis
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/merge-tp19805328p19807495.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Merge question

2009-02-26 Thread Vadlamani, Subrahmanyam {FLNA}
Hi:
I am a new R user. I have the following question and would appreciate your input

Data1 (data frame 1)
p1,d1,d2 (p1 is text and d1 and d2 are numeric)
xyz,10,25

Data2 (data frame 2)
p1,d1,d2
xyz,11,15

Now I want to create a new data frame that looks like so below. The fields d1 
and s2 are summed by the product key.
Data3
p1,d1,d2
xyz,21 (sum of 10 from Data1 and 11 from Data2),40 (sum of 25 from Data1 and 15 
from Data2)

Any other examples of merge you may have will be appreciated. Thanks.
Satish

__
R-help@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.


[R] Merge vectors

2009-07-22 Thread MarcioRibeiro

Hi listers,
I would like to merge two vectors as follows...
A<-c(3,5,7,18,43,85,91,98,100,130,230,487) #data values
B<-c(10,5,5,10,8,11,2,7,3,11,10)  #random numbers (sample)
I would like to set the vector of random numbers according to the order set
of the vector of data values...
The result would be: (130,43,43,130,98,230,5,91,7,230,130)
I could do this with merging, but I would need to set a primary key to merge
the vectors... Is there a way of doing directly...
Thanks in advance,
Marcio


-- 
View this message in context: 
http://www.nabble.com/Merge-vectors-tp24612997p24612997.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] merge in function

2007-12-06 Thread qian z
I used merge() in a function, but it doesn't return correct data frame. 
   
  add.name <- function(data, x)
   
  {
   
  ...
  ...
   
  newfile <- merge(data, resid, by =0, all.x=TRUE, all.y= FALSE)
  newfile
   
   
  }
   
   

   
-

[[alternative HTML version deleted]]

__
R-help@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.


[R] merge with rownames?

2008-04-03 Thread Mark Kimpel
Can merge be tricked into merging via rownames as opposed to via contents of
a particular column? I have two data.frames with overlapping, but out of
order, rownames, but no column contents in common and would like to merge
without cbinding the rownames to the data.frames.
Mark

-- 
Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN  46074

(317) 490-5129 Work, & Mobile & VoiceMail
(317) 663-0513 Home (no voice mail please)

**

[[alternative HTML version deleted]]

__
R-help@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.


[R] merge/combine data

2008-10-16 Thread Dirkheld

Hi,

I have the following data imported from a csv file
   user_id site_id   name
11  11  februari
21  11   redbook
31  11  tips
73   6 sleep
83   6monitoring
93   6 alarm

Which I would like to merge/combine into
   user_id site_id   name
11  11  februari, redbook, tips
23   6 sleep, monitoring, alarm
3 .

So I would like to combine data from similar user_id and site_id in one line
with a merge of the 'name'.



-- 
View this message in context: 
http://www.nabble.com/merge-combine-data-tp20009538p20009538.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] merge character strings

2008-12-02 Thread mentor_

Hi,

how can I do the following in R?:

vec <- c("a", "b", "c")
magic.
print(str)
"abc"

or even better:
"(a,b,c)"?

Cheers
-- 
View this message in context: 
http://www.nabble.com/merge-character-strings-tp20790116p20790116.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Merge question

2009-02-26 Thread milton ruser
Hi there,

something like this?


Data1<-read.table(stdin(), head=T, sep=",")
p1,d1,d2
xyz,10,25
kmz,100,250

Data2<-read.table(stdin(), head=T, sep=",")
p1,d1,d2
xyz,11,15
kmz,110,150

Data1
Data2
Data3<-data.frame(rbind(Data1,Data2))
Data3
Data3.sum<-aggregate(Data3[,c("d1","d2")], list(Data3$p1), sum)
Data3.sum

Best wishes

miltinho astronauta
brazil
On Thu, Feb 26, 2009 at 2:52 PM, Vadlamani, Subrahmanyam {FLNA} <
subrahmanyam.vadlam...@fritolay.com> wrote:

> Hi:
> I am a new R user. I have the following question and would appreciate your
> input
>
> Data1 (data frame 1)
> p1,d1,d2 (p1 is text and d1 and d2 are numeric)
> xyz,10,25
>
> Data2 (data frame 2)
> p1,d1,d2
> xyz,11,15
>
> Now I want to create a new data frame that looks like so below. The fields
> d1 and s2 are summed by the product key.
> Data3
> p1,d1,d2
> xyz,21 (sum of 10 from Data1 and 11 from Data2),40 (sum of 25 from Data1
> and 15 from Data2)
>
> Any other examples of merge you may have will be appreciated. Thanks.
> Satish
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Merge question

2009-02-26 Thread Marc Schwartz
on 02/26/2009 11:52 AM Vadlamani, Subrahmanyam {FLNA} wrote:
> Hi:
> I am a new R user. I have the following question and would appreciate your 
> input
> 
> Data1 (data frame 1)
> p1,d1,d2 (p1 is text and d1 and d2 are numeric)
> xyz,10,25
> 
> Data2 (data frame 2)
> p1,d1,d2
> xyz,11,15
> 
> Now I want to create a new data frame that looks like so below. The fields d1 
> and s2 are summed by the product key.
> Data3
> p1,d1,d2
> xyz,21 (sum of 10 from Data1 and 11 from Data2),40 (sum of 25 from Data1 and 
> 15 from Data2)
> 
> Any other examples of merge you may have will be appreciated. Thanks.
> Satish

Given the nature of your data, having the same column structure with
repeated keys, I would not use merge(), but rbind() the two data frames
together and then use aggregate():

DF <- rbind(Data1, Data2)

> DF
   p1 d1 d2
1 xyz 10 25
2 xyz 11 15

> aggregate(DF[-1], list(p1 = DF$p1), sum)
   p1 d1 d2
1 xyz 21 40


See ?rbind and ?aggregate

If you search the list archives:

  RSiteSearch("merge")

you will yield hundreds of posts showing the use of that particular
function.

HTH,

Marc Schwartz

__
R-help@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.


Re: [R] Merge vectors

2009-07-22 Thread Steve Lianoglou

Hi,

On Jul 22, 2009, at 3:31 PM, MarcioRibeiro wrote:



Hi listers,
I would like to merge two vectors as follows...
A<-c(3,5,7,18,43,85,91,98,100,130,230,487) #data values
B<-c(10,5,5,10,8,11,2,7,3,11,10)  #random numbers (sample)
I would like to set the vector of random numbers according to the  
order set

of the vector of data values...
The result would be: (130,43,43,130,98,230,5,91,7,230,130)


R> A[B]
[1] 130  43  43 130  98 230   5  91   7 230 130

-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@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.


Re: [R] Merge vectors

2009-07-22 Thread Erik Iverson
A[B]

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of MarcioRibeiro
Sent: Wednesday, July 22, 2009 2:31 PM
To: r-help@r-project.org
Subject: [R] Merge vectors


Hi listers,
I would like to merge two vectors as follows...
A<-c(3,5,7,18,43,85,91,98,100,130,230,487) #data values
B<-c(10,5,5,10,8,11,2,7,3,11,10)  #random numbers (sample)
I would like to set the vector of random numbers according to the order set
of the vector of data values...
The result would be: (130,43,43,130,98,230,5,91,7,230,130)
I could do this with merging, but I would need to set a primary key to merge
the vectors... Is there a way of doing directly...
Thanks in advance,
Marcio


-- 
View this message in context: 
http://www.nabble.com/Merge-vectors-tp24612997p24612997.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.

__
R-help@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.


Re: [R] Merge vectors

2009-07-22 Thread Mark Knecht
Sort of like this?

> A<-c(3,5,7,18,43,85,91,98,100,130,230,487) #data values
> B<-c(10,5,5,10,8,11,2,7,3,11,10)  #random numbers (sample)
>
> C = A[B]
> C
 [1] 130  43  43 130  98 230   5  91   7 230 130

On Wed, Jul 22, 2009 at 2:08 PM, Erik Iverson wrote:
> A[B]
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of MarcioRibeiro
> Sent: Wednesday, July 22, 2009 2:31 PM
> To: r-help@r-project.org
> Subject: [R] Merge vectors
>
>
> Hi listers,
> I would like to merge two vectors as follows...
> A<-c(3,5,7,18,43,85,91,98,100,130,230,487) #data values
> B<-c(10,5,5,10,8,11,2,7,3,11,10)  #random numbers (sample)
> I would like to set the vector of random numbers according to the order set
> of the vector of data values...
> The result would be: (130,43,43,130,98,230,5,91,7,230,130)
> I could do this with merging, but I would need to set a primary key to merge
> the vectors... Is there a way of doing directly...
> Thanks in advance,
> Marcio
>
>
> --
> View this message in context: 
> http://www.nabble.com/Merge-vectors-tp24612997p24612997.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>
> __
> R-help@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.
>

__
R-help@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.


Re: [R] merge in function

2007-12-06 Thread Marc Schwartz

On Thu, 2007-12-06 at 09:27 -0800, qian z wrote:
> I used merge() in a function, but it doesn't return correct data frame. 
>
>   add.name <- function(data, x)
>
>   {
>
>   ...
>   ...
>
>   newfile <- merge(data, resid, by =0, all.x=TRUE, all.y= FALSE)
>   newfile
>
>
>   }

You are going to need to give us more information. 

It is not clear what you mean by not returning the correct data frame.
Why is it not correct? 

Where and what is 'resid'?  

What is 'x' and how is it used in the function?  

What is 'by = 0'? The 'by' argument values need to be quoted.

Please provide a small reproducible example as per the Posting Guide.

HTH,

Marc Schwartz

__
R-help@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.


Re: [R] merge in function

2007-12-07 Thread John Kane
I think we need some actual sample code .  Also by= 0
seems a bit funny.
--- qian z <[EMAIL PROTECTED]> wrote:

> I used merge() in a function, but it doesn't return
> correct data frame. 
>
>   add.name <- function(data, x)
>
>   {
>
>   ...
>   ...
>
>   newfile <- merge(data, resid, by =0, all.x=TRUE,
> all.y= FALSE)
>   newfile
>
>
>   }
>

__
R-help@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.


[R] merge table rows (\multirow)

2009-01-11 Thread Felipe Carrillo
Hi:
I need help merging rows.
I am trying to merge the 'Month' column using \multirow. For example for the 
column 'Week' I want July to be merged into one row(weeks 27,28,29,30) and so 
on for the following weeks.
Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to show 
an example.


\documentclass[11pt]{article}
\usepackage{longtable,verbatim}
\title{How to implement multirow with Sweave}
\begin{document}
\maketitle
<>=
sampDat <- "Month, Week, Est.passage, Med.FL
July 27665   34
July 282,232   35
July 299,241   35
July 3028,464  35
Aug  3141,049  35
Aug 32 82,216  35
Aug 33 230,411  35
Aug 34 358,541  35
Sept 35747,839  35
Sept 36459,682  36
Sept 37609,567  36
Sept 38979,475  36
Sept 39837,189  36"
DF <- read.table(textConnection(sampDat), header = TRUE)
attach(DF)
@
\begin{verbatim}
Using Hmisc.
\end{verbatim}
<>=
library(Hmisc)
mytab <- data.frame(DF)
latex(DF,label="tab:hola",longtable=FALSE,caption='Sample table.')
@
\begin{verbatim}
Or with xtable
\end{verbatim}
<>=
library(xtable)
table2 <- data.frame(DF)
table2 <- xtable(DF,label='tab2',caption='table 2 with xtable',digits=0)
print(table2,floating=FALSE)
@
\end{document}

Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA

__
R-help@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.


[R] merge table rows (\multirow)

2009-01-12 Thread Felipe Carrillo
Hi:
This is what my table should look like:

Month Week   EstpassageMedFL
July-27456634
-28256835
-29328736
-30462337
Aug--31863237
   --32423638
   --33763239
   --34598440
Sept-35125840
-36423541
-37257342
-38423-43
I don't want to reshape my dataset, I basically want a latex table showing only 
one value on the first column instead of repeating the  month over and over. I 
know this can be done with \multirow if the table is created manually. Since 
this table is created dynamically on the fly I don't know how to use \multirow 
like that. Hope is clear. Thanks


--- On Mon, 1/12/09, Dieter Menne  wrote:

> From: Dieter Menne 
> Subject: Re: [R] merge table rows (\multirow)
> To: r-h...@stat.math.ethz.ch
> Date: Monday, January 12, 2009, 12:41 AM
> Felipe Carrillo  yahoo.com>
> writes:
> 
> > I need help merging rows.
> > I am trying to merge the 'Month' column using
> \multirow. For example for the
> column 'Week' I want July to be
> > merged into one row(weeks 27,28,29,30) and so on for
> the following weeks.
> > Below, I am creating a PDF using Sweave,
> MikTex,R-2.8.1 and windows XP to show
> an example.
> 
> 
> I don't fully understand how the table should look
> like, mainly
> how the Week display should look like. I suggest that you
> try to
> not do the main formatting in latex/xtable, but rather use
> function reshape or package reshape (below). The following
> should give you a starter, I know it is not fully what you
> want.
> 
> Dieter
> 
> 
> sampDat <- "Month Week Estpassage MedFL
> July 27   665 34
> July 28   2232   35
> July 29   9241   35
> July 30   28464   35
> Aug  31   41049   35
> Aug 32   82216   35
> Aug 33   230411  35
> Aug 34   358541  35
> Sept 35   747839  35
> Sept 36   459682  36
> Sept 37   609567  36
> Sept 38   979475  36
> Sept 39   837189  36"
> DF <- read.table(textConnection(sampDat), header = TRUE)
> 
> library(reshape)
> DFm = melt(DF,id=c("Month","Week"))
> cast(DFm,variable~Month+Week)

__
R-help@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.


[R] merge two data sets

2008-06-03 Thread kayj

I would like to merge “data1 “that contains 100 unique ID’s with  another
data set “data 2” with 150 ID’s and the age of those individuals ( the ID in
data1 is a subset of the ID in data 2) I  would like to merge these data1
with data2 and have the result of the merge to have the ID ordered as in
data1.

Can this be done in R?


-- 
View this message in context: 
http://www.nabble.com/merge-two-data-sets-tp17636278p17636278.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] merge with rownames?

2008-04-03 Thread Chuck Cleland
On 4/3/2008 10:47 AM, Mark Kimpel wrote:
> Can merge be tricked into merging via rownames as opposed to via contents of
> a particular column? I have two data.frames with overlapping, but out of
> order, rownames, but no column contents in common and would like to merge
> without cbinding the rownames to the data.frames.
> Mark

   The details section of the help page for merge suggests you can use 
either merge(..., by=0) or merge(..., by="row.names").

?merge

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@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.


Re: [R] merge/combine data

2008-10-16 Thread jim holtman
try this:

> x <- read.table(textConnection("  user_id site_id   name
+ 11  11  februari
+ 21  11   redbook
+ 31  11  tips
+ 73   6 sleep
+ 83   6monitoring
+ 93   6 alarm"), header=TRUE)
> closeAllConnections()
> y <- lapply(split(x, list(x$user_id, x$site_id), drop=TRUE), function(.data){
+ data.frame(user_id=.data$user_id[1], site_id=.data$site_id[1],
+ name=paste(as.character(.data$name), collapse=','))
+ })
> do.call(rbind, y)
 user_id site_id   name
3.63   6 sleep,monitoring,alarm
1.11   1  11  februari,redbook,tips


On Thu, Oct 16, 2008 at 4:43 AM, Dirkheld <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I have the following data imported from a csv file
>   user_id site_id   name
> 11  11  februari
> 21  11   redbook
> 31  11  tips
> 73   6 sleep
> 83   6monitoring
> 93   6 alarm
>
> Which I would like to merge/combine into
>   user_id site_id   name
> 11  11  februari, redbook, tips
> 23   6 sleep, monitoring, alarm
> 3 .
>
> So I would like to combine data from similar user_id and site_id in one line
> with a merge of the 'name'.
>
>
>
> --
> View this message in context: 
> http://www.nabble.com/merge-combine-data-tp20009538p20009538.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>



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

What is the problem that you are trying to solve?

__
R-help@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.


[R] merge 2 txt file

2008-11-04 Thread Alessandro
Hi all,

 

I have two txt file with X,Y,Z column and I need to merge together

 

I tried 

file_all <- merge("file1.txt","file2.txt")

but I don't sure about the result. Is It this code correct?

Thanks Ale 


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] merge character strings

2008-12-02 Thread Dimitris Rizopoulos

check at paste(), e.g.,

vec <- c("a", "b", "c")
paste(vec, collapse = "")


I hope it helps.

Best,
Dimitris


mentor_ wrote:

Hi,

how can I do the following in R?:

vec <- c("a", "b", "c")
magic.
print(str)
"abc"

Cheers


--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
R-help@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.


[R] Merge two variables together

2009-03-31 Thread jimdare

Hello,

If I have two variables:

v1<-c(2,4,2,3,7,8)
v2<-c(0,0,0,0,0,0)

how can I merge them to form

v3<-2,0,4,0,2,0,3,0,7,0,8,0

I am trying to use this to get an xyplot to label every second x tick mark
(i.e. by replacing v1 with every second year and v2 with "").
-- 
View this message in context: 
http://www.nabble.com/Merge-two-variables-together-tp22817164p22817164.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Merge partially duplicated rows

2009-08-03 Thread Rnewbie

Dear all,

I have a dataset, and I wanted to merge the rows with duplicated IDs by
calculating the means or medians from the duplicate rows. I tried using the
command duplicated(x), but it only tells where the duplicated rows are.

Any suggestions will be appreciated.
-- 
View this message in context: 
http://www.nabble.com/Merge-partially-duplicated-rows-tp24790752p24790752.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] merge table rows (\multirow)

2009-01-12 Thread Dieter Menne
Felipe Carrillo  yahoo.com> writes:

> I need help merging rows.
> I am trying to merge the 'Month' column using \multirow. For example for the
column 'Week' I want July to be
> merged into one row(weeks 27,28,29,30) and so on for the following weeks.
> Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to show
an example.

Thanks for the goodexample (Note to the "you did not quote completely" 
complainants: please use a thread reader to see the OP. This list
is clutter with too many > >> >>>).

I don't fully understand how the table should look like, mainly
how the Week display should look like. I suggest that you try to
not do the main formatting in latex/xtable, but rather use
function reshape or package reshape (below). The following
should give you a starter, I know it is not fully what you want.

I had some problems with the commas in you data set, so
I removed these.

Dieter


sampDat <- "Month Week Estpassage MedFL
July 27665   34
July 28223235
July 29924135
July 3028464   35
Aug  3141049   35
Aug 32 82216   35
Aug 33 230411  35
Aug 34 358541  35
Sept 35747839  35
Sept 36459682  36
Sept 37609567  36
Sept 38979475  36
Sept 39837189  36"
DF <- read.table(textConnection(sampDat), header = TRUE)

library(reshape)
DFm = melt(DF,id=c("Month","Week"))
cast(DFm,variable~Month+Week)

__
R-help@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.


Re: [R] merge table rows (\multirow)

2009-01-12 Thread Dieter Menne



Felipe Carrillo wrote:
> 
> I am trying to merge the 'Month' column using \multirow. For example for
> the column 'Week' I want July to be merged into one row(weeks 27,28,29,30)
> and so on for the following weeks.
> Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to
> show an example.
> 
> 

.. Example removed and partially regenerated below

Another try; had a bad hour this morning, too many typos. 
This comes closer to what you want, but not exactly. 
You might try to manually call format.df which is implicitly 
called in latex, and massage that.
Again, I do not know if this is easier with xtable.

If you want to post latex samples, it is not really
necessary to include it in Sweave. The example
below works fine for testing.

Dieter


library(Hmisc)
sampDat <- "Month Week Estpassage MedFL
July 27665   34
July 28223235
July 29924135
July 3028464   35
Aug  3141049   35
Aug 32 82216   35
Aug 33 230411  35
Aug 34 358541  35
Sept 35747839  35
Sept 36459682  36
Sept 37609567  36
Sept 38979475  36
Sept 39837189  36"
DF <- read.table(textConnection(sampDat), header = TRUE)
row.names(DF)=DF$Week
latex(DF[,-2],label="tab:hola",longtable=FALSE,caption='Sample table.',
  rowname="",
  rgroup=unique(DF$Month),n.rgroup=table(DF$Month))

-- 
View this message in context: 
http://www.nabble.com/merge-table-rows-%28%5Cmultirow%29-tp21408818p21417983.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] merge table rows (\multirow)

2009-01-12 Thread Gabor Grothendieck
Look at the rgroup and n.rgroup arguments of ?latex
function in Hmisc package or ?print.xtable in xtable package.

On Mon, Jan 12, 2009 at 1:48 PM, Felipe Carrillo
 wrote:
> Hi:
> This is what my table should look like:
>
> Month Week   EstpassageMedFL
> July-27456634
>-28256835
>-29328736
>-30462337
> Aug--31863237
>   --32423638
>   --33763239
>   --34598440
> Sept-35125840
>-36423541
>-37257342
>-38423-43
> I don't want to reshape my dataset, I basically want a latex table showing 
> only one value on the first column instead of repeating the  month over and 
> over. I know this can be done with \multirow if the table is created 
> manually. Since this table is created dynamically on the fly I don't know how 
> to use \multirow like that. Hope is clear. Thanks
>
>
> --- On Mon, 1/12/09, Dieter Menne  wrote:
>
>> From: Dieter Menne 
>> Subject: Re: [R] merge table rows (\multirow)
>> To: r-h...@stat.math.ethz.ch
>> Date: Monday, January 12, 2009, 12:41 AM
>> Felipe Carrillo  yahoo.com>
>> writes:
>>
>> > I need help merging rows.
>> > I am trying to merge the 'Month' column using
>> \multirow. For example for the
>> column 'Week' I want July to be
>> > merged into one row(weeks 27,28,29,30) and so on for
>> the following weeks.
>> > Below, I am creating a PDF using Sweave,
>> MikTex,R-2.8.1 and windows XP to show
>> an example.
>>
>>
>> I don't fully understand how the table should look
>> like, mainly
>> how the Week display should look like. I suggest that you
>> try to
>> not do the main formatting in latex/xtable, but rather use
>> function reshape or package reshape (below). The following
>> should give you a starter, I know it is not fully what you
>> want.
>>
>> Dieter
>>
>>
>> sampDat <- "Month Week Estpassage MedFL
>> July 27   665 34
>> July 28   2232   35
>> July 29   9241   35
>> July 30   28464   35
>> Aug  31   41049   35
>> Aug 32   82216   35
>> Aug 33   230411  35
>> Aug 34   358541  35
>> Sept 35   747839  35
>> Sept 36   459682  36
>> Sept 37   609567  36
>> Sept 38   979475  36
>> Sept 39   837189  36"
>> DF <- read.table(textConnection(sampDat), header = TRUE)
>>
>> library(reshape)
>> DFm = melt(DF,id=c("Month","Week"))
>> cast(DFm,variable~Month+Week)
>
> __
> R-help@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.
>

__
R-help@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.


Re: [R] merge table rows (\multirow)

2009-01-12 Thread Felipe Carrillo
Thanks a lot Dieter, I'll play a little bit with it. Also thanks for the hint 
on how to post a latex reproducible example.



--- On Mon, 1/12/09, Dieter Menne  wrote:

> From: Dieter Menne 
> Subject: Re: [R] merge table rows (\multirow)
> To: r-help@r-project.org
> Date: Monday, January 12, 2009, 8:32 AM
> Felipe Carrillo wrote:
> > 
> > I am trying to merge the 'Month' column using
> \multirow. For example for
> > the column 'Week' I want July to be merged
> into one row(weeks 27,28,29,30)
> > and so on for the following weeks.
> > Below, I am creating a PDF using Sweave,
> MikTex,R-2.8.1 and windows XP to
> > show an example.
> > 
> > 
> 
> .. Example removed and partially regenerated below
> 
> Another try; had a bad hour this morning, too many typos. 
> This comes closer to what you want, but not exactly. 
> You might try to manually call format.df which is
> implicitly 
> called in latex, and massage that.
> Again, I do not know if this is easier with xtable.
> 
> If you want to post latex samples, it is not really
> necessary to include it in Sweave. The example
> below works fine for testing.
> 
> Dieter
> 
> 
> library(Hmisc)
> sampDat <- "Month Week Estpassage MedFL
> July 27  665   34
> July 28  223235
> July 29  924135
> July 30  28464   35
> Aug  31  41049   35
> Aug 32   82216   35
> Aug 33   230411  35
> Aug 34   358541  35
> Sept 35  747839  35
> Sept 36  459682  36
> Sept 37  609567  36
> Sept 38  979475  36
> Sept 39  837189  36"
> DF <- read.table(textConnection(sampDat), header = TRUE)
> row.names(DF)=DF$Week
> latex(DF[,-2],label="tab:hola",longtable=FALSE,caption='Sample
> table.', rowname="",rgroup=unique(DF$Month),n.rgroup=table(DF$Month))
> 
> -- 
> View this message in context:
> http://www.nabble.com/merge-table-rows-%28%5Cmultirow%29-tp21408818p21417983.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@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.

__
R-help@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.


[R] Merge two vectors into one.

2009-01-28 Thread patricia garcía gonzález

Hi all, 

I have two vectors like this:


  x <- c( "Y", "H", NA,  NA )

y <- c( NA,  "H", NA,  "B" )

And would like to make one vector with the common elements, and the element 
available only in one of the vectors.


  res <- c( "Y",  "H", NA,  "B" )


Thanks, 

Patricia



> From: neptune...@hotmail.com
> To: r-help@r-project.org
> Date: Wed, 28 Jan 2009 14:15:20 +
> Subject: [R] initial value in 'vmmin' is not finite
> 
> 
> Dear r helpers
>  
> I run the following code for nested logit and got a message that 
>  
> Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = 
> "BFGS") :   initial value in 'vmmin' is not finite
> What does this mean? and how can I correct it?
>  
> Thank you
> June
>  
> > yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> 
> > dim(yogurt)[1] 1278425> choice = yogurt[,2:5]> price=yogurt[,14:17]> 
> > feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=n)> 
> > yop=cbind(constant,feature[,1],price[,1])> 
> > dan=cbind(constant,feature[,2],price[,2])> 
> > hil=cbind(constant,feature[,3],price[,3])> wt=cbind(feature[,4],price[,4])> 
> > > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = 
> > x[5]+ x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = 
> > rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = 
> > rbind(x[5],x[6])+ rho=exp(x[7])/(1+exp(x[7]))+ ey = exp((yop%*%con1)/rho)+ 
> > ed = exp((dan%*%con2)/rho)+ eh = exp((hil%*%con3)/rho)+ ew = 
> > exp((wt%*%con4)/rho)+ ev = ey+ed+eh+ew+ den=(ey+ed+eh+ew)+ iv = 
> > rho*log(den)+ pp=exp(x[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* 
> > ed/den+ pr3 =pp* eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ 
> > likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt!
 [,!
>  4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = 
> optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in 
> optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") :   
> initial value in 'vmmin' is not finite
> 
> _
> 
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

_


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] merge two data sets

2008-06-03 Thread Moshe Olshansky
Where do you want to place ID's which are in data2 but NOT in data1?


--- On Wed, 4/6/08, kayj <[EMAIL PROTECTED]> wrote:

> From: kayj <[EMAIL PROTECTED]>
> Subject: [R]  merge two data sets
> To: r-help@r-project.org
> Received: Wednesday, 4 June, 2008, 9:45 AM
> I would like to merge “data1 “that contains 100 unique
> ID’s with  another
> data set “data 2” with 150 ID’s and the age of those
> individuals ( the ID in
> data1 is a subset of the ID in data 2) I  would like to
> merge these data1
> with data2 and have the result of the merge to have the ID
> ordered as in
> data1.
> 
> Can this be done in R?
> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/merge-two-data-sets-tp17636278p17636278.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] merge two data sets

2008-06-04 Thread kayj

since they are not in data1 , I do not want them to be in the merge result.



Moshe Olshansky-2 wrote:
> 
> Where do you want to place ID's which are in data2 but NOT in data1?
> 
> 
> --- On Wed, 4/6/08, kayj <[EMAIL PROTECTED]> wrote:
> 
>> From: kayj <[EMAIL PROTECTED]>
>> Subject: [R]  merge two data sets
>> To: r-help@r-project.org
>> Received: Wednesday, 4 June, 2008, 9:45 AM
>> I would like to merge “data1 “that contains 100 unique
>> ID’s with  another
>> data set “data 2” with 150 ID’s and the age of those
>> individuals ( the ID in
>> data1 is a subset of the ID in data 2) I  would like to
>> merge these data1
>> with data2 and have the result of the merge to have the ID
>> ordered as in
>> data1.
>> 
>> Can this be done in R?
>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/merge-two-data-sets-tp17636278p17636278.html
>> Sent from the R help mailing list archive at Nabble.com.
>> 
>> __
>> R-help@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.
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/merge-two-data-sets-tp17636278p17652782.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] merge two data sets

2008-06-04 Thread Mark Wardle
Please see ?merge

In particular, see all.x parameter.

Mark

2008/6/4 kayj <[EMAIL PROTECTED]>:
>
> I would like to merge "data1 "that contains 100 unique ID's with  another
> data set "data 2" with 150 ID's and the age of those individuals ( the ID in
> data1 is a subset of the ID in data 2) I  would like to merge these data1
> with data2 and have the result of the merge to have the ID ordered as in
> data1.
>
> Can this be done in R?
>
>
> --
> View this message in context: 
> http://www.nabble.com/merge-two-data-sets-tp17636278p17636278.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>
> __
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> __
>



-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

__
R-help@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.


Re: [R] merge 2 txt file

2008-11-04 Thread jim holtman
What exactly are you trying to do?  You need to provide at least a
sample of the input and then what you would expect as output.  Exactly
what to the columns contain and how you expect to 'merge' them.

On Tue, Nov 4, 2008 at 6:52 PM, Alessandro <[EMAIL PROTECTED]> wrote:
> Hi all,
>
>
>
> I have two txt file with X,Y,Z column and I need to merge together
>
>
>
> I tried
>
> file_all <- merge("file1.txt","file2.txt")
>
> but I don't sure about the result. Is It this code correct?
>
> Thanks Ale
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>



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

What is the problem that you are trying to solve?

__
R-help@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.


Re: [R] merge 2 txt file

2008-11-05 Thread John Kane
> From: Alessandro <[EMAIL PROTECTED]>
> Subject: [R] merge 2 txt file
> To: [EMAIL PROTECTED], r-help@r-project.org
> Received: Tuesday, November 4, 2008, 6:52 PM
> Hi all,
> 
>  
> 
> I have two txt file with X,Y,Z column and I need to merge
> together
> 
>  
> 
> I tried 
> 
> file_all <-
> merge("file1.txt","file2.txt")
> 
> but I don't sure about the result. Is It this code
> correct?

Who knows?  We need some information on what the files contain and how you want 
to "merge" them.

The best thing to do is to follow the posting guidelines and provide a small 
working example of what the data looks like and what you are trying to do.

You might want to take a look at ?cbind and ?rbind.

__
R-help@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.


Re: [R] Merge two variables together

2009-03-31 Thread jim holtman
try this:

> v1<-c(2,4,2,3,7,8)
> v2<-c(0,0,0,0,0,0)
> as.vector(rbind(v1,v2))
 [1] 2 0 4 0 2 0 3 0 7 0 8 0


On Tue, Mar 31, 2009 at 7:46 PM, jimdare  wrote:
>
> Hello,
>
> If I have two variables:
>
> v1<-c(2,4,2,3,7,8)
> v2<-c(0,0,0,0,0,0)
>
> how can I merge them to form
>
> v3<-2,0,4,0,2,0,3,0,7,0,8,0
>
> I am trying to use this to get an xyplot to label every second x tick mark
> (i.e. by replacing v1 with every second year and v2 with "").
> --
> View this message in context: 
> http://www.nabble.com/Merge-two-variables-together-tp22817164p22817164.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>



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

What is the problem that you are trying to solve?

__
R-help@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.


Re: [R] Merge two variables together

2009-03-31 Thread jimdare

Thanks guys


jimdare wrote:
> 
> Hello,
> 
> If I have two variables:
> 
> v1<-c(2,4,2,3,7,8)
> v2<-c(0,0,0,0,0,0)
> 
> how can I merge them to form
> 
> v3<-2,0,4,0,2,0,3,0,7,0,8,0
> 
> I am trying to use this to get an xyplot to label every second x tick mark
> (i.e. by replacing v1 with every second year and v2 with "").
> 

-- 
View this message in context: 
http://www.nabble.com/Merge-two-variables-together-tp22817164p22819193.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Merge partially duplicated rows

2009-08-03 Thread David Winsemius


On Aug 3, 2009, at 9:24 AM, Rnewbie wrote:



Dear all,

I have a dataset, and I wanted to merge the rows with duplicated IDs  
by
calculating the means or medians from the duplicate rows. I tried  
using the
command duplicated(x), but it only tells where the duplicated rows  
are.


You might want to look at the ave function. It will calculate a  
function within IDs and you can assign that as another row in the  
datafrme before you exclude the duplicates.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


Re: [R] Merge partially duplicated rows

2009-08-03 Thread David Winsemius


On Aug 3, 2009, at 7:12 PM, David Winsemius wrote:



On Aug 3, 2009, at 9:24 AM, Rnewbie wrote:



Dear all,

I have a dataset, and I wanted to merge the rows with duplicated  
IDs by
calculating the means or medians from the duplicate rows. I tried  
using the
command duplicated(x), but it only tells where the duplicated rows  
are.


You might want to look at the ave function. It will calculate a  
function within IDs and you can assign that as another row in the  
datafrme before you exclude the duplicates.

^^

err... I meant to say another column.

> tst <- data.frame(ID = sample(c("1234", "4567", "2346"), 10,  
replace=TRUE), val=rnorm(10))

> tst
 ID val
1  2346  0.22659389
2  2346  0.46835154
3  2346 -0.53702251
4  2346 -1.00187606
5  1234  0.90843566
6  2346 -0.59654370
7  4567 -0.04355647
8  1234  0.65332120
9  4567 -2.22517105
10 1234 -0.26911187
> tst$IDmn <- ave(tst$val, tst$ID) #default function for ave is mean  
but others can be used

> tst
 ID val   IDmn
1  2346  0.22659389 -0.2880994
2  2346  0.46835154 -0.2880994
3  2346 -0.53702251 -0.2880994
4  2346 -1.00187606 -0.2880994
5  1234  0.90843566  0.4308817
6  2346 -0.59654370 -0.2880994
7  4567 -0.04355647 -1.1343638
8  1234  0.65332120  0.4308817
9  4567 -2.22517105 -1.1343638
10 1234 -0.26911187  0.4308817



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


Re: [R] Merge partially duplicated rows

2009-08-04 Thread Rnewbie

Thanks very much :handshake:


David Winsemius wrote:
> 
> 
> You might want to look at the ave function. It will calculate a  
> function within IDs and you can assign that as another row in the  
> datafrme before you exclude the duplicates.
> 
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Merge-partially-duplicated-rows-tp24790752p24803781.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Merge two vectors into one.

2009-01-28 Thread patricia garcía gonzález

Hi, 



Sorry, the answers are yes yes yes. And thank you for your idea it works 
perfectly.


Regards



Patricia



> Date: Wed, 28 Jan 2009 16:01:11 +0100
> Subject: Re: [R] Merge two vectors into one.
> From: csa...@rmki.kfki.hu
> To: kurtney...@hotmail.com
> CC: r-help@r-project.org
> 
> Is position important? The vectors always have the same length? They
> always have the same entry if both are not NA?
> 
> If yes, yes and yes, then
> 
> res <- ifelse( is.na(x), y, x)
> 
> does what you want. Otherwise please explain better what you want.
> 
> Gabor
> 
> On Wed, Jan 28, 2009 at 3:54 PM, patricia garcía gonzález
>  wrote:
> >
> > Hi all,
> >
> > I have two vectors like this:
> >
> >
> >  x <- c( "Y", "H", NA,  NA )
> >
> >y <- c( NA,  "H", NA,  "B" )
> >
> > And would like to make one vector with the common elements, and the element 
> > available only in one of the vectors.
> >
> >
> >  res <- c( "Y",  "H", NA,  "B" )
> >
> >
> > Thanks,
> >
> > Patricia
> >
> 
> -- 
> Gabor Csardi  UNIL DGM

_


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Merge two vectors into one.

2009-01-28 Thread Gábor Csárdi
Is position important? The vectors always have the same length? They
always have the same entry if both are not NA?

If yes, yes and yes, then

res <- ifelse( is.na(x), y, x)

does what you want. Otherwise please explain better what you want.

Gabor

On Wed, Jan 28, 2009 at 3:54 PM, patricia garcía gonzález
 wrote:
>
> Hi all,
>
> I have two vectors like this:
>
>
>  x <- c( "Y", "H", NA,  NA )
>
>y <- c( NA,  "H", NA,  "B" )
>
> And would like to make one vector with the common elements, and the element 
> available only in one of the vectors.
>
>
>  res <- c( "Y",  "H", NA,  "B" )
>
>
> Thanks,
>
> Patricia
>

-- 
Gabor Csardi  UNIL DGM

__
R-help@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.


Re: [R] Merge two vectors into one.

2009-01-28 Thread Dimitris Rizopoulos

you could start by something like the following:

x <- c("Y", "H", NA, NA)
y <- c(NA, "H", NA, "B")

ifelse(is.na(x), y, x)


I hope it helps.

Best,
Dimitris


patricia garcía gonzález wrote:
Hi all, 


I have two vectors like this:


  x <- c( "Y", "H", NA,  NA )

y <- c( NA,  "H", NA,  "B" )

And would like to make one vector with the common elements, and the element 
available only in one of the vectors.


  res <- c( "Y",  "H", NA,  "B" )


Thanks, 


Patricia




From: neptune...@hotmail.com
To: r-help@r-project.org
Date: Wed, 28 Jan 2009 14:15:20 +
Subject: [R] initial value in 'vmmin' is not finite


Dear r helpers
 
I run the following code for nested logit and got a message that 
 
Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") :   initial value in 'vmmin' is not finite

What does this mean? and how can I correct it?
 
Thank you

June
 

yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> dim(yogurt)[1] 1278425> choice = 
yogurt[,2:5]> price=yogurt[,14:17]> feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=n)> 
yop=cbind(constant,feature[,1],price[,1])> dan=cbind(constant,feature[,2],price[,2])> hil=cbind(constant,feature[,3],price[,3])> 
wt=cbind(feature[,4],price[,4])> > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = x[5]+ x6 = x[6]+ x7 = 
x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = rbind(x[5],x[6])+ 
rho=exp(x[7])/(1+exp(x[7]))+ ey = exp((yop%*%con1)/rho)+ ed = exp((dan%*%con2)/rho)+ eh = exp((hil%*%con3)/rho)+ ew = exp((wt%*%con4)/rho)+ 
ev = ey+ed+eh+ew+ den=(ey+ed+eh+ew)+ iv = rho*log(den)+ pp=exp(x[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* ed/den+ pr3 =pp* eh/den+ 
pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt

!

 [,!

 4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = 
optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in optim(c(0, 0, 0, 
0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") :   initial value in 'vmmin' is not 
finite

_



[[alternative HTML version deleted]]

__
R-help@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.


_


[[alternative HTML version deleted]]

__
R-help@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.



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
R-help@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.


[R] merge numerous columns of unequal length

2008-05-05 Thread T.D.Rudolph

I have numerous objects, each containing continuous data representing the
same variable, movement rate, yet each having a different number of rows.  
e.g.
d1<-as.matrix(rnorm(5))
d2<-as.matrix(rnorm(3))
d3<-as.matrix(rnorm(6))

How can I merge these three columns side-by-side in order to create a table
regardless of the difference in length?  I wish to analyze the output in a
spreadsheet format.

Thanks!
Tyler
-- 
View this message in context: 
http://www.nabble.com/merge-numerous-columns-of-unequal-length-tp17071464p17071464.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Merge data frame and keep unmatched

2009-06-10 Thread Etienne B. Racine

Hi,

With two data sets, one complete and another one partial, I would like to
merge them and keep the unmatched lines. The problem is that merge() dosen't
keep the unmatched lines. Is there another function that I could use to
merge the data frames.

Example:

completedf <- expand.grid(alpha=letters[1:3],beta=1:3)
partdf <- data.frame(
alpha= c('a','a','c'),
beta = c(1,3,2),
val = c(2,6,4))

mergedf <- merge(x=completedf, y=partdf, by=c('alpha','beta'))
# it only kept the common rows
nrow(mergedf)

Thanks, 
Etienne
-- 
View this message in context: 
http://www.nabble.com/Merge-data-frame-and-keep-unmatched-tp23962874p23962874.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] merge numerous columns of unequal length

2008-05-05 Thread markleeds
you can do below but there's no way of getting arounf having NAs in your 
final matrix.


d1<-as.matrix(rnorm(5))
d2<-as.matrix(rnorm(3))
d3<-as.matrix(rnorm(6))

templist <- list(d1,d2,d3)
maxnum <- max(sapply(templist,length))
print(maxnum)

temp <- lapply(templist,function(.mat) {
  if (nrow(.mat) < maxnum) {
 return(c(.mat,rep(NA,maxnum-nrow(.mat
   } else {
 return(.mat)
   }
})

finalmat <- as.matrix(do.call(cbind,temp))
print(finalmat)



On Mon, May 5, 2008 at  6:46 PM, T.D.Rudolph wrote:

I have numerous objects, each containing continuous data representing 
the
same variable, movement rate, yet each having a different number of 
rows.  e.g.

d1<-as.matrix(rnorm(5))
d2<-as.matrix(rnorm(3))
d3<-as.matrix(rnorm(6))

How can I merge these three columns side-by-side in order to create a 
table
regardless of the difference in length?  I wish to analyze the output 
in a

spreadsheet format.

Thanks!
Tyler
--
View this message in context: 
http://www.nabble.com/merge-numerous-columns-of-unequal-length-tp17071464p17071464.html

Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


__
R-help@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.


Re: [R] merge numerous columns of unequal length

2008-05-05 Thread Henrique Dallazuanna
Try this also:

sapply(list(d1, d2, d3), "[", 1:max(sapply(list(d1, d2, d3), length)))

On Mon, May 5, 2008 at 7:46 PM, T.D.Rudolph <[EMAIL PROTECTED]>
wrote:

>
> I have numerous objects, each containing continuous data representing the
> same variable, movement rate, yet each having a different number of rows.
> e.g.
> d1<-as.matrix(rnorm(5))
> d2<-as.matrix(rnorm(3))
> d3<-as.matrix(rnorm(6))
>
> How can I merge these three columns side-by-side in order to create a
> table
> regardless of the difference in length?  I wish to analyze the output in a
> spreadsheet format.
>
> Thanks!
> Tyler
> --
> View this message in context:
> http://www.nabble.com/merge-numerous-columns-of-unequal-length-tp17071464p17071464.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] merge numerous columns of unequal length

2008-05-06 Thread Patrick Burns

As the answers you've received suggest, you
can use a list.  Or you could have two
vectors: one with the data, the other with the
group identity.  The latter format is likely more
convenient for a lot of analyses.

Since your data are not inherently rectangular,
it is probably best to get the idea of spreadsheet
out of your head.  (It is probably best anyway.)

Patrick Burns
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

T.D.Rudolph wrote:

I have numerous objects, each containing continuous data representing the
same variable, movement rate, yet each having a different number of rows.  
e.g.

d1<-as.matrix(rnorm(5))
d2<-as.matrix(rnorm(3))
d3<-as.matrix(rnorm(6))

How can I merge these three columns side-by-side in order to create a table
regardless of the difference in length?  I wish to analyze the output in a
spreadsheet format.

Thanks!
Tyler



__
R-help@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.


Re: [R] merge numerous columns of unequal length

2008-05-06 Thread T.D.Rudolph

Indeed both options are salable, though I agree the latter may be more
convenient.
Merci!


Patrick Burns wrote:
> 
> As the answers you've received suggest, you
> can use a list.  Or you could have two
> vectors: one with the data, the other with the
> group identity.  The latter format is likely more
> convenient for a lot of analyses.
> 
> Since your data are not inherently rectangular,
> it is probably best to get the idea of spreadsheet
> out of your head.  (It is probably best anyway.)
> 
> Patrick Burns
> [EMAIL PROTECTED]
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
> 
> T.D.Rudolph wrote:
>> I have numerous objects, each containing continuous data representing the
>> same variable, movement rate, yet each having a different number of rows.  
>> e.g.
>> d1<-as.matrix(rnorm(5))
>> d2<-as.matrix(rnorm(3))
>> d3<-as.matrix(rnorm(6))
>>
>> How can I merge these three columns side-by-side in order to create a
>> table
>> regardless of the difference in length?  I wish to analyze the output in
>> a
>> spreadsheet format.
>>
>> Thanks!
>> Tyler
>>
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/merge-numerous-columns-of-unequal-length-tp17071464p17086657.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Merge data frame and keep unmatched

2009-07-13 Thread Matthew Dowle
Or if you need it to be fast,  try data.table.   X[Y] is a join when X and Y 
are both data.tables. X[Y] is a left join, Y[X] is a right join. 'nomatch' 
controls the inner/outer join i.e. what happens for unmatched rows.   This 
is much faster than merge().

"Gabor Grothendieck"  wrote in message 
news:971536df0906100704q433f5f99ld3f9c23e69d95...@mail.gmail.com...
Try:

merge(completedf, partdf, all.x = TRUE)

or

library(sqldf) # see http://sqldf.googlecode.com
sqldf("select * from completedf left join partdf using(beta, alpha)")


On Wed, Jun 10, 2009 at 9:56 AM, Etienne B. Racine 
wrote:
>
> Hi,
>
> With two data sets, one complete and another one partial, I would like to
> merge them and keep the unmatched lines. The problem is that merge() 
> dosen't
> keep the unmatched lines. Is there another function that I could use to
> merge the data frames.
>
> Example:
>
> completedf <- expand.grid(alpha=letters[1:3],beta=1:3)
> partdf <- data.frame(
> alpha= c('a','a','c'),
> beta = c(1,3,2),
> val = c(2,6,4))
>
> mergedf <- merge(x=completedf, y=partdf, by=c('alpha','beta'))
> # it only kept the common rows
> nrow(mergedf)
>
> Thanks,
> Etienne
> --
> View this message in context: 
> http://www.nabble.com/Merge-data-frame-and-keep-unmatched-tp23962874p23962874.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>

__
R-help@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.


[R] merge zoo objects contained in a list

2009-08-11 Thread stephen sefick
I would like to merge zoo objects that are stored in a list into one
big zoo object with one index for all of the observations.

I have created the list (74 dataframes) with the code below, and have
tried the do.call(merge, foo) in the call and the output is not what I
expected.  Any help would be greatly appreciated.

Stephen Sefick

###level logger read
in#
read.ll <- function(path, file.name)
{
if(!require(chron))
   stop("Package 'chron' required but not installed.")
if(!require(zoo))
   stop("Package 'zoo' required but not installed.")
list.of.files <- list.files(path)
length.files <- length(list.of.files)
df <- vector(mode = "list", length = length.files)
fnames <- paste(path, list.of.files, sep = "/")

for(i in seq(along = list.of.files))
{
df[[i]] <- read.table(fnames[i], skip=45, as.is=TRUE)
#lengths of the dataframes because the last to lines of the .lev
file are garbage#
length.1 <- length(df[[i]][,1])
length.2 <- length(df[[i]][,1])-1
#remove the garbage
df[[i]] <- df[[i]][-c(length.1, length.2),]
#make chron class for datetime
df[[i]] <- data.frame(chron(as.character(df[[i]][,1]),
as.character(df[[i]][,2]), format=c(dates="Y/m/d", times="H:M:S")),
as.numeric(df[[i]][,3]), as.numeric(df[[i]][,4]),
as.factor(list.of.files[[i]]))
#change names of columns
names(df[[i]]) <- c("datetime", "level", "temp", "site")
#make zoo object
df[[i]] <- zoo(df[[i]], df[[i]][,"datetime"])
}
#merge all of the lists into one huge dataframe
merged <- do.call(merge, df)


return(merged)
}
-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help@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.


[R] Merge data frames but with a twist.

2009-08-27 Thread Tony Breyal
Dear all,

Question: How to merge two data frames such that new column are added
in a particular way?

I'm not actually sure how to best articulate my question to be honest,
so i hope showing you what I want to achieve will communicate my
question better.

Lets say I have two data frames:

> DF1 <- data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=1:2, 
> Datetime=c('08/26/2009 9:30 AM', '08/26/2009 9:30 AM')))

> DF2 <- data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=3:4, 
> Datetime=c('08/26/2009 11:30 AM', '08/26/2009 11:30 AM')))

And then let us merge these:

> DF3 <- merge(DF1, DF2, all=TRUE)

   Show MeasureDatetime
1 Firefly 1  08/26/2009 9:30 AM
2 Firefly 3  08/26/2009 11:30 AM
3 Red Dwarf   2  08/26/2009 9:30 AM
4 Red Dwarf   4  08/26/2009 11:30 AM


What i would like to do is merge the data frames such that i end up
with the following:

Show   08/26/2009 9:30 AM08/26/2009 11:30 AM
Firefly  13
Red Dwarf24

my reason for doing this is so that i can plot a time series somehow.

I hope the formating stays when i post this message and that what i'm
trying to do is easy to understand. Thank you kindly for any help in
advance.

Tony

__
R-help@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.


Re: [R] Merge data frame and keep unmatched

2009-06-10 Thread Marc Schwartz


On Jun 10, 2009, at 8:56 AM, Etienne B. Racine wrote:



Hi,

With two data sets, one complete and another one partial, I would  
like to
merge them and keep the unmatched lines. The problem is that merge()  
dosen't
keep the unmatched lines. Is there another function that I could use  
to

merge the data frames.

Example:

completedf <- expand.grid(alpha=letters[1:3],beta=1:3)
partdf <- data.frame(
alpha= c('a','a','c'),
beta = c(1,3,2),
val = c(2,6,4))

mergedf <- merge(x=completedf, y=partdf, by=c('alpha','beta'))
# it only kept the common rows
nrow(mergedf)

Thanks,
Etienne




Is this what you want?

> merge(x=completedf, y=partdf, by=c('alpha','beta'), all = TRUE)
  alpha beta val
1 a1   2
2 a2  NA
3 a3   6
4 b1  NA
5 b2  NA
6 b3  NA
7 c1  NA
8 c2   4
9 c3  NA

Note the 'all', 'all.x' and 'all.y' arguments...

HTH,

Marc Schwartz

__
R-help@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.


Re: [R] Merge data frame and keep unmatched

2009-06-10 Thread Gabor Grothendieck
Try:

merge(completedf, partdf, all.x = TRUE)

or

library(sqldf) # see http://sqldf.googlecode.com
sqldf("select * from completedf left join partdf using(beta, alpha)")


On Wed, Jun 10, 2009 at 9:56 AM, Etienne B. Racine wrote:
>
> Hi,
>
> With two data sets, one complete and another one partial, I would like to
> merge them and keep the unmatched lines. The problem is that merge() dosen't
> keep the unmatched lines. Is there another function that I could use to
> merge the data frames.
>
> Example:
>
> completedf <- expand.grid(alpha=letters[1:3],beta=1:3)
> partdf <- data.frame(
>        alpha= c('a','a','c'),
>        beta = c(1,3,2),
>        val = c(2,6,4))
>
> mergedf <- merge(x=completedf, y=partdf, by=c('alpha','beta'))
> # it only kept the common rows
> nrow(mergedf)
>
> Thanks,
> Etienne
> --
> View this message in context: 
> http://www.nabble.com/Merge-data-frame-and-keep-unmatched-tp23962874p23962874.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>

__
R-help@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.


[R] Merge or combine data frames with missing columns

2008-12-29 Thread Mark Heckmann

Hi R-experts,

suppose I have a list with containing data frame elements:

[[1]]
(Intercept)  y1  y2  y3  y4 
 -6.64  0.761  0.383  0.775  0.163
 
[[2]]
(Intercept)  y2  y3  
-3.858 0.854  0.834 

Now I want to put them into ONE dataframe like this:
   (Intercept)   y1  y2 y3   y4 
   1   -6.64  0.761  0.383  0.775  0.163
   2 -3.858  NA   0.854  0.834NA

The problem I encounter is that not always all possible columns (Intercept,  
y1,  y2, y3,  y4) exist or at least have NA entries .

I cannot figure out how (e.g. with merge)...

TIA, Mark


-- 
Mark Heckmann (Dipl. Wirt.-Ing.)
phone +49 (0) 421/1614618

Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a

__
R-help@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.


Re: [R] merge zoo objects contained in a list

2009-08-11 Thread Gabor Grothendieck
Can you provide something reproducible and elaborate on
what "expected" means.

On Tue, Aug 11, 2009 at 4:11 PM, stephen sefick wrote:
> I would like to merge zoo objects that are stored in a list into one
> big zoo object with one index for all of the observations.
>
> I have created the list (74 dataframes) with the code below, and have
> tried the do.call(merge, foo) in the call and the output is not what I
> expected.  Any help would be greatly appreciated.
>
> Stephen Sefick
>
> ###level logger read
> in#
> read.ll <- function(path, file.name)
>        {
> if(!require(chron))
>   stop("Package 'chron' required but not installed.")
> if(!require(zoo))
>   stop("Package 'zoo' required but not installed.")
> list.of.files <- list.files(path)
> length.files <- length(list.of.files)
> df <- vector(mode = "list", length = length.files)
> fnames <- paste(path, list.of.files, sep = "/")
>
>                for(i in seq(along = list.of.files))
>                {
>                df[[i]] <- read.table(fnames[i], skip=45, as.is=TRUE)
>                #lengths of the dataframes because the last to lines of the 
> .lev
> file are garbage#
>                length.1 <- length(df[[i]][,1])
>                length.2 <- length(df[[i]][,1])-1
>                #remove the garbage
>                df[[i]] <- df[[i]][-c(length.1, length.2),]
>                #make chron class for datetime
>                df[[i]] <- data.frame(chron(as.character(df[[i]][,1]),
> as.character(df[[i]][,2]), format=c(dates="Y/m/d", times="H:M:S")),
> as.numeric(df[[i]][,3]), as.numeric(df[[i]][,4]),
> as.factor(list.of.files[[i]]))
>                #change names of columns
>                names(df[[i]]) <- c("datetime", "level", "temp", "site")
>                #make zoo object
>                df[[i]] <- zoo(df[[i]], df[[i]][,"datetime"])
>                }
>                        #merge all of the lists into one huge dataframe
>                        merged <- do.call(merge, df)
>
>
> return(merged)
> }
> --
> Stephen Sefick
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>                                                                -K. Mullis
>
> __
> R-help@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.
>

__
R-help@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.


Re: [R] merge zoo objects contained in a list

2009-08-12 Thread stephen sefick
All of the data frames in the list (list of 74)  have the same column
names, and some have the exact same index values, while others have
out of sync, but in the same range.  I can send a small example off
list.  I will look at it again when I get into work this morning to
see if I can fix it.
thanks for all of the help,

Stephen Sefick

On Tue, Aug 11, 2009 at 6:33 PM, Gabor
Grothendieck wrote:
> Can you provide something reproducible and elaborate on
> what "expected" means.
>
> On Tue, Aug 11, 2009 at 4:11 PM, stephen sefick wrote:
>> I would like to merge zoo objects that are stored in a list into one
>> big zoo object with one index for all of the observations.
>>
>> I have created the list (74 dataframes) with the code below, and have
>> tried the do.call(merge, foo) in the call and the output is not what I
>> expected.  Any help would be greatly appreciated.
>>
>> Stephen Sefick
>>
>> ###level logger read
>> in#
>> read.ll <- function(path, file.name)
>>        {
>> if(!require(chron))
>>   stop("Package 'chron' required but not installed.")
>> if(!require(zoo))
>>   stop("Package 'zoo' required but not installed.")
>> list.of.files <- list.files(path)
>> length.files <- length(list.of.files)
>> df <- vector(mode = "list", length = length.files)
>> fnames <- paste(path, list.of.files, sep = "/")
>>
>>                for(i in seq(along = list.of.files))
>>                {
>>                df[[i]] <- read.table(fnames[i], skip=45, as.is=TRUE)
>>                #lengths of the dataframes because the last to lines of the 
>> .lev
>> file are garbage#
>>                length.1 <- length(df[[i]][,1])
>>                length.2 <- length(df[[i]][,1])-1
>>                #remove the garbage
>>                df[[i]] <- df[[i]][-c(length.1, length.2),]
>>                #make chron class for datetime
>>                df[[i]] <- data.frame(chron(as.character(df[[i]][,1]),
>> as.character(df[[i]][,2]), format=c(dates="Y/m/d", times="H:M:S")),
>> as.numeric(df[[i]][,3]), as.numeric(df[[i]][,4]),
>> as.factor(list.of.files[[i]]))
>>                #change names of columns
>>                names(df[[i]]) <- c("datetime", "level", "temp", "site")
>>                #make zoo object
>>                df[[i]] <- zoo(df[[i]], df[[i]][,"datetime"])
>>                }
>>                        #merge all of the lists into one huge dataframe
>>                        merged <- do.call(merge, df)
>>
>>
>> return(merged)
>> }
>> --
>> Stephen Sefick
>>
>> Let's not spend our time and resources thinking about things that are
>> so little or so large that all they really do for us is puff us up and
>> make us feel like gods.  We are mammals, and have not exhausted the
>> annoying little problems of being mammals.
>>
>>                                                                -K. Mullis
>>
>> __
>> R-help@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.
>>
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help@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.


Re: [R] Merge data frames but with a twist.

2009-08-27 Thread Henrique Dallazuanna
Try this:

xtabs(as.numeric(Measure) ~ Show + Datetime, data = DF3)


On Thu, Aug 27, 2009 at 8:04 AM, Tony Breyal wrote:

> Dear all,
>
> Question: How to merge two data frames such that new column are added
> in a particular way?
>
> I'm not actually sure how to best articulate my question to be honest,
> so i hope showing you what I want to achieve will communicate my
> question better.
>
> Lets say I have two data frames:
>
> > DF1 <- data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=1:2,
> Datetime=c('08/26/2009 9:30 AM', '08/26/2009 9:30 AM')))
>
> > DF2 <- data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=3:4,
> Datetime=c('08/26/2009 11:30 AM', '08/26/2009 11:30 AM')))
>
> And then let us merge these:
>
> > DF3 <- merge(DF1, DF2, all=TRUE)
>
>   Show MeasureDatetime
> 1 Firefly 1  08/26/2009 9:30 AM
> 2 Firefly 3  08/26/2009 11:30 AM
> 3 Red Dwarf   2  08/26/2009 9:30 AM
> 4 Red Dwarf   4  08/26/2009 11:30 AM
>
>
> What i would like to do is merge the data frames such that i end up
> with the following:
>
> Show   08/26/2009 9:30 AM08/26/2009 11:30 AM
> Firefly  13
> Red Dwarf24
>
> my reason for doing this is so that i can plot a time series somehow.
>
> I hope the formating stays when i post this message and that what i'm
> trying to do is easy to understand. Thank you kindly for any help in
> advance.
>
> Tony
>
> __
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Merge data frames but with a twist.

2009-08-27 Thread Stephen Tucker
You may want to use the reshape package for this task:

> library(reshape)
> recast(DF3,Show ~ Datetime, id.var=names(DF3),value="Measure")
   Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM
1   Firefly   3  1
2 Red Dwarf   4  2

If you want to plot time series, you can do something like the following

> mydf <- .Last.value ## save the output from above to mydf
> library(zoo)
> zobj <- zoo(`mode<-`(t(mydf),"numeric"),
> as.chron(strptime(names(mydf)[-1],"%m/%d/%Y %I:%M %p")))
> plot(zobj)

(zobj is a time series object of the zoo class)



- Original Message 
From: Tony Breyal 
To: r-help@r-project.org
Sent: Thursday, August 27, 2009 4:04:30 AM
Subject: [R] Merge data frames but with a twist.

Dear all,

Question: How to merge two data frames such that new column are added
in a particular way?

I'm not actually sure how to best articulate my question to be honest,
so i hope showing you what I want to achieve will communicate my
question better.

Lets say I have two data frames:

> DF1 <- data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=1:2, 
> Datetime=c('08/26/2009 9:30 AM', '08/26/2009 9:30 AM')))

> DF2 <- data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=3:4, 
> Datetime=c('08/26/2009 11:30 AM', '08/26/2009 11:30 AM')))

And then let us merge these:

> DF3 <- merge(DF1, DF2, all=TRUE)

   Show MeasureDatetime
1 Firefly 1  08/26/2009 9:30 AM
2 Firefly 3  08/26/2009 11:30 AM
3 Red Dwarf   2  08/26/2009 9:30 AM
4 Red Dwarf   4  08/26/2009 11:30 AM


What i would like to do is merge the data frames such that i end up
with the following:

Show   08/26/2009 9:30 AM08/26/2009 11:30 AM
Firefly  13
Red Dwarf24

my reason for doing this is so that i can plot a time series somehow.

I hope the formating stays when i post this message and that what i'm
trying to do is easy to understand. Thank you kindly for any help in
advance.

Tony

__
R-help@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.

__
R-help@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.


Re: [R] Merge data frames but with a twist.

2009-08-27 Thread Gabor Grothendieck
On Thu, Aug 27, 2009 at 9:55 AM, Stephen Tucker wrote:
> You may want to use the reshape package for this task:
>
>> library(reshape)
>> recast(DF3,Show ~ Datetime, id.var=names(DF3),value="Measure")
>       Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM
> 1   Firefly                   3                  1
> 2 Red Dwarf                   4                  2
>
> If you want to plot time series, you can do something like the following
>
>> mydf <- .Last.value ## save the output from above to mydf
>> library(zoo)
>> zobj <- zoo(`mode<-`(t(mydf),"numeric"),
>>             as.chron(strptime(names(mydf)[-1],"%m/%d/%Y %I:%M %p")))
>> plot(zobj)
>
> (zobj is a time series object of the zoo class)

Note that as.chron can take % codes directly so the as.chron portion
can be shortened to:

as.chron(names(mydf)[-1],"%m/%d/%Y %I:%M %p")

__
R-help@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.


Re: [R] Merge data frames but with a twist.

2009-08-27 Thread Stephen Tucker
Ah, thanks always - 
I originally thought as.chron() was required to have all fields (m/d/y 
hh:mm:ss) as for chron() but I see that the former passes its 'format' argument 
to  as.POSIXct()
Good deal!
Stephen



- Original Message 
From: Gabor Grothendieck 
To: Stephen Tucker 
Cc: Tony Breyal ; r-help@r-project.org
Sent: Thursday, August 27, 2009 7:27:26 AM
Subject: Re: [R] Merge data frames but with a twist.

On Thu, Aug 27, 2009 at 9:55 AM, Stephen Tucker wrote:
> You may want to use the reshape package for this task:
>
>> library(reshape)
>> recast(DF3,Show ~ Datetime, id.var=names(DF3),value="Measure")
>   Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM
> 1   Firefly   3  1
> 2 Red Dwarf   4  2
>
> If you want to plot time series, you can do something like the following
>
>> mydf <- .Last.value ## save the output from above to mydf
>> library(zoo)
>> zobj <- zoo(`mode<-`(t(mydf),"numeric"),
>> as.chron(strptime(names(mydf)[-1],"%m/%d/%Y %I:%M %p")))
>> plot(zobj)
>
> (zobj is a time series object of the zoo class)

Note that as.chron can take % codes directly so the as.chron portion
can be shortened to:

as.chron(names(mydf)[-1],"%m/%d/%Y %I:%M %p")

__
R-help@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.


Re: [R] Merge data frames but with a twist.

2009-08-27 Thread Gabor Grothendieck
The inconsistency arose in order to satisfy backward compatibility
while giving chron a direct way to use % codes.

chron used its own format specification so it would have been difficult
to add % codes there; however, as.chron, at the time, did not support a
format specification at all so it was still possible to add a format specifier
using % codes without disrupting existing code.

On Thu, Aug 27, 2009 at 2:21 PM, Stephen Tucker wrote:
> Ah, thanks always -
> I originally thought as.chron() was required to have all fields (m/d/y 
> hh:mm:ss) as for chron() but I see that the former passes its 'format' 
> argument to  as.POSIXct()
> Good deal!
> Stephen
>
>
>
> - Original Message 
> From: Gabor Grothendieck 
> To: Stephen Tucker 
> Cc: Tony Breyal ; r-help@r-project.org
> Sent: Thursday, August 27, 2009 7:27:26 AM
> Subject: Re: [R] Merge data frames but with a twist.
>
> On Thu, Aug 27, 2009 at 9:55 AM, Stephen Tucker wrote:
>> You may want to use the reshape package for this task:
>>
>>> library(reshape)
>>> recast(DF3,Show ~ Datetime, id.var=names(DF3),value="Measure")
>>       Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM
>> 1   Firefly                   3                  1
>> 2 Red Dwarf                   4                  2
>>
>> If you want to plot time series, you can do something like the following
>>
>>> mydf <- .Last.value ## save the output from above to mydf
>>> library(zoo)
>>> zobj <- zoo(`mode<-`(t(mydf),"numeric"),
>>>             as.chron(strptime(names(mydf)[-1],"%m/%d/%Y %I:%M %p")))
>>> plot(zobj)
>>
>> (zobj is a time series object of the zoo class)
>
> Note that as.chron can take % codes directly so the as.chron portion
> can be shortened to:
>
> as.chron(names(mydf)[-1],"%m/%d/%Y %I:%M %p")
>
>
>
>
>

__
R-help@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.


[R] Merge data frames but prefer values in one

2009-09-10 Thread JiHO

Hello everyone,

My problem is better explained with an example:

> x=data.frame(a=1:4,b=1:4,c=rnorm(4))
> x
 a b  c
1 1 1 -0.8821089
2 2 2 -0.7082583
3 3 3 -0.5948835
4 4 4 -1.8571443
> y=data.frame(a=c(1,3),b=3,c=rnorm(2))
> y
 a bc
1 1 3 -0.273155973
2 3 3  0.009517862

Now I want to merge x and y by columns a and b, hence creating a  
data.frame with all a:b combinations observed in x and y. That's  
easily done with merge:


> merge(x,y,by=c("a","b"),all=T)
 a bc.x  c.y
1 1 1 -0.8821089   NA
2 1 3 NA -0.273155973
3 2 2 -0.7082583   NA
4 3 3 -0.5948835  0.009517862
5 4 4 -1.8571443   NA

But rather than two c columns I would want the merge to:
- keep the value in x if there is no corresponding value in y
- keep the value in y if there is no corresponding value in x
- prefer the value in y when the a:b combination exists in both x and y

So basically I want my result to look like:
 a b  c
1 1 1 -0.8821089
2 1 3 -0.2731559
3 2 2 -0.7082583
4 3 3  0.0095178
5 4 4 -1.8571443

I can't find a combinations of options for merge that does this. Is  
there another fonction that would do that or do I have to resort to  
some post-processing after merge? It seems that it might be something  
like a "right merge" for data bases but I don't know this world at  
all. I would be happy to look into sqldf if that allows to do things  
like that.


Thanks in advance. Sincerely,

JiHO
---
http://maururu.net

__
R-help@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.


Re: [R] Merge or combine data frames with missing columns

2008-12-29 Thread Rowe, Brian Lee Yung (Portfolio Analytics)
Mark,

I think ?rbind should work for you.

Regards,
Brian

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Mark Heckmann
Sent: Monday, December 29, 2008 9:18 AM
To: r-help@r-project.org
Subject: [R] Merge or combine data frames with missing columns



Hi R-experts,

suppose I have a list with containing data frame elements:

[[1]]
(Intercept)  y1  y2  y3  y4 
 -6.64  0.761  0.383  0.775  0.163
 
[[2]]
(Intercept)  y2  y3  
-3.858 0.854  0.834 

Now I want to put them into ONE dataframe like this:
   (Intercept)   y1  y2 y3   y4 
   1   -6.64  0.761  0.383  0.775  0.163
   2 -3.858  NA   0.854  0.834NA

The problem I encounter is that not always all possible columns (Intercept,  
y1,  y2, y3,  y4) exist or at least have NA entries .

I cannot figure out how (e.g. with merge)...

TIA, Mark


-- 
Mark Heckmann (Dipl. Wirt.-Ing.)
phone +49 (0) 421/1614618

Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a

__
R-help@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.

--
This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically indicated, 
this message is not an offer to sell or a solicitation of any investment 
products or other financial product or service, an official confirmation of any 
transaction, or an official statement of Merrill Lynch. Subject to applicable 
law, Merrill Lynch may monitor, review and retain e-communications (EC) 
traveling through its networks/systems. The laws of the country of each 
sender/recipient may impact the handling of EC, and EC may be archived, 
supervised and produced in countries other than the country in which you are 
located. This message cannot be guaranteed to be secure or error-free. This 
message is subject to terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.
--

__
R-help@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.


Re: [R] Merge or combine data frames with missing columns

2008-12-29 Thread Charles C. Berry

On Mon, 29 Dec 2008, Mark Heckmann wrote:



Hi R-experts,

suppose I have a list with containing data frame elements:

[[1]]
(Intercept)  y1  y2  y3  y4
-6.64  0.761  0.383  0.775  0.163

[[2]]
(Intercept)  y2  y3
-3.858 0.854  0.834

Now I want to put them into ONE dataframe like this:
  (Intercept)   y1  y2 y3   y4
  1   -6.64  0.761  0.383  0.775  0.163
  2 -3.858  NA   0.854  0.834NA

The problem I encounter is that not always all possible columns (Intercept,  
y1,  y2, y3,  y4) exist or at least have NA entries .

I cannot figure out how (e.g. with merge)...


Just use a nested for loop:


my.list <- list(c(a=1,b=2,c=3),c(a=10,b=20),c(g=7,h=8))
dat <- data.frame()
for(i in seq(along=my.list)) for(j in names(my.list[[i]])) dat[i,j] <- 
my.list[[i]][j]



If what you actually wanted was a _matrix_, and if it is rather large, 
faster solutions might be possible using tapply or sapply.


HTH,

Chuck




TIA, Mark


--
Mark Heckmann (Dipl. Wirt.-Ing.)
phone +49 (0) 421/1614618

Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a

__
R-help@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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@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.


Re: [R] Merge or combine data frames with missing columns

2008-12-29 Thread Lauri Nikkinen
How about this solution

g1 <- data.frame(ic = 1, y1 = 2, y2 = 3, y3 = 4, y4 = 5)
g2 <- data.frame(ic = 2, y2 = 6, y3 = 7)
g <- list(g1, g2)
library(gregmisc)
do.call(smartbind, g)

-Lauri

__
R-help@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.


Re: [R] Merge or combine data frames with missing columns

2008-12-29 Thread Henrique Dallazuanna
Try this:

do.call(rbind, lapply(l, "[", unique(unlist(sapply(l, names)

Where "l" is your list.

On Mon, Dec 29, 2008 at 12:18 PM, Mark Heckmann wrote:

>
> Hi R-experts,
>
> suppose I have a list with containing data frame elements:
>
> [[1]]
> (Intercept)  y1  y2  y3  y4
>  -6.64  0.761  0.383  0.775  0.163
>
> [[2]]
> (Intercept)  y2  y3
> -3.858 0.854  0.834
>
> Now I want to put them into ONE dataframe like this:
>   (Intercept)   y1  y2 y3   y4
>   1   -6.64  0.761  0.383  0.775  0.163
>   2 -3.858  NA   0.854  0.834NA
>
> The problem I encounter is that not always all possible columns (Intercept,
>  y1,  y2, y3,  y4) exist or at least have NA entries .
>
> I cannot figure out how (e.g. with merge)...
>
> TIA, Mark
>
>
> --
> Mark Heckmann (Dipl. Wirt.-Ing.)
> phone +49 (0) 421/1614618
>
> Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL
> für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a
>
> __
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Merge or combine data frames with missing columns

2008-12-29 Thread Mark Heckmann
thanks for the elegant solution!

It worked out fine in my case, but when I tried to understand what it does I 
discovered one little issue.

l <- list(data.frame(a=1, b=2), data.frame(a=2, c=3))
do.call(rbind, lapply(l, "[", unique(unlist(sapply(l, names)

will not work. Neither the following list.

l <- list(data.frame(a=1, b=2), data.frame(a=2, c=3, d=5))

I am not able to figure out why. Does anyone know what could be done to fix it?

TIA, Mark


 Original-Nachricht 
> Datum: Mon, 29 Dec 2008 16:17:22 -0200
> Von: "Henrique Dallazuanna" 
> An: "Mark Heckmann" 
> CC: r-help@r-project.org
> Betreff: Re: [R] Merge or combine data frames with missing columns

> Try this:
> 
> do.call(rbind, lapply(l, "[", unique(unlist(sapply(l, names)
> 
> Where "l" is your list.
> 
> On Mon, Dec 29, 2008 at 12:18 PM, Mark Heckmann
> wrote:
> 
> >
> > Hi R-experts,
> >
> > suppose I have a list with containing data frame elements:
> >
> > [[1]]
> > (Intercept)  y1  y2  y3  y4
> >  -6.64  0.761  0.383  0.775  0.163
> >
> > [[2]]
> > (Intercept)  y2  y3
> > -3.858 0.854  0.834
> >
> > Now I want to put them into ONE dataframe like this:
> >   (Intercept)   y1  y2 y3  
> y4
> >   1   -6.64  0.761  0.383  0.775  0.163
> >   2 -3.858  NA   0.854  0.834NA
> >
> > The problem I encounter is that not always all possible columns
> (Intercept,
> >  y1,  y2, y3,  y4) exist or at least have NA entries .
> >
> > I cannot figure out how (e.g. with merge)...
> >
> > TIA, Mark
> >
> >
> > --
> > Mark Heckmann (Dipl. Wirt.-Ing.)
> > phone +49 (0) 421/1614618
> >
> > Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL
> > für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a
> >
> > __
> > R-help@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.
> >
> 
> 
> 
> -- 
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O

-- 
Mark Heckmann (Dipl. Wirt.-Ing.)
phone +49 (0) 421/1614618

__
R-help@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.


Re: [R] Merge or combine data frames with missing columns

2008-12-29 Thread hadley wickham
Or even more simply:

On Mon, Dec 29, 2008 at 12:17 PM, Henrique Dallazuanna  wrote:
> Try this:
>
> do.call(rbind, lapply(l, "[", unique(unlist(sapply(l, names)
>
> Where "l" is your list.

Or even more simply:

library(plyr)
do.call(rbind.fill, l)

which doesn't get the variable order quite right, but should in a
future version.

Hadley

-- 
http://had.co.nz/

__
R-help@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.


Re: [R] Merge or combine data frames with missing columns

2008-12-30 Thread Henrique Dallazuanna
Try this:

do.call(rbind, lapply(lapply(l, unlist), "[", unique(unlist(c(sapply(l,
names))

On Mon, Dec 29, 2008 at 7:35 PM, Mark Heckmann  wrote:

> thanks for the elegant solution!
>
> It worked out fine in my case, but when I tried to understand what it does
> I discovered one little issue.
>
> l <- list(data.frame(a=1, b=2), data.frame(a=2, c=3))
> do.call(rbind, lapply(l, "[", unique(unlist(sapply(l, names)
>
> will not work. Neither the following list.
>
> l <- list(data.frame(a=1, b=2), data.frame(a=2, c=3, d=5))
>
> I am not able to figure out why. Does anyone know what could be done to fix
> it?
>
> TIA, Mark
>
>
>  Original-Nachricht 
> > Datum: Mon, 29 Dec 2008 16:17:22 -0200
> > Von: "Henrique Dallazuanna" 
> > An: "Mark Heckmann" 
> > CC: r-help@r-project.org
> > Betreff: Re: [R] Merge or combine data frames with missing columns
>
> > Try this:
> >
> > do.call(rbind, lapply(l, "[", unique(unlist(sapply(l, names)
> >
> > Where "l" is your list.
> >
> > On Mon, Dec 29, 2008 at 12:18 PM, Mark Heckmann
> > wrote:
> >
> > >
> > > Hi R-experts,
> > >
> > > suppose I have a list with containing data frame elements:
> > >
> > > [[1]]
> > > (Intercept)  y1  y2  y3  y4
> > >  -6.64  0.761  0.383  0.775  0.163
> > >
> > > [[2]]
> > > (Intercept)  y2  y3
> > > -3.858 0.854  0.834
> > >
> > > Now I want to put them into ONE dataframe like this:
> > >   (Intercept)   y1  y2 y3
> > y4
> > >   1   -6.64  0.761  0.383  0.775  0.163
> > >   2 -3.858  NA   0.854  0.834NA
> > >
> > > The problem I encounter is that not always all possible columns
> > (Intercept,
> > >  y1,  y2, y3,  y4) exist or at least have NA entries .
> > >
> > > I cannot figure out how (e.g. with merge)...
> > >
> > > TIA, Mark
> > >
> > >
> > > --
> > > Mark Heckmann (Dipl. Wirt.-Ing.)
> > > phone +49 (0) 421/1614618
> > >
> > > Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL
> > > für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a
> > >
> > > __
> > > R-help@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.
> > >
> >
> >
> >
> > --
> > Henrique Dallazuanna
> > Curitiba-Paraná-Brasil
> > 25° 25' 40" S 49° 16' 22" O
>
> --
> Mark Heckmann (Dipl. Wirt.-Ing.)
> phone +49 (0) 421/1614618
>
> Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen:
> http://www.gmx.net/de/go/multimessenger
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Merge data frames but prefer values in one

2009-09-10 Thread Henrique Dallazuanna
Try this:

xy <- merge(x, y, by = c("a","b"),all = TRUE)
xy$c <- ifelse(rowSums(!is.na(.x <- xy[, c('c.x', 'c.y')])) > 1, .x[,1],
rowSums(.x, na.rm = TRUE))
xy

On Thu, Sep 10, 2009 at 12:21 PM, JiHO  wrote:

> Hello everyone,
>
> My problem is better explained with an example:
>
> > x=data.frame(a=1:4,b=1:4,c=rnorm(4))
> > x
>  a b  c
> 1 1 1 -0.8821089
> 2 2 2 -0.7082583
> 3 3 3 -0.5948835
> 4 4 4 -1.8571443
> > y=data.frame(a=c(1,3),b=3,c=rnorm(2))
> > y
>  a bc
> 1 1 3 -0.273155973
> 2 3 3  0.009517862
>
> Now I want to merge x and y by columns a and b, hence creating a data.frame
> with all a:b combinations observed in x and y. That's easily done with
> merge:
>
> > merge(x,y,by=c("a","b"),all=T)
>  a bc.x  c.y
> 1 1 1 -0.8821089   NA
> 2 1 3 NA -0.273155973
> 3 2 2 -0.7082583   NA
> 4 3 3 -0.5948835  0.009517862
> 5 4 4 -1.8571443   NA
>
> But rather than two c columns I would want the merge to:
> - keep the value in x if there is no corresponding value in y
> - keep the value in y if there is no corresponding value in x
> - prefer the value in y when the a:b combination exists in both x and y
>
> So basically I want my result to look like:
>  a b  c
> 1 1 1 -0.8821089
> 2 1 3 -0.2731559
> 3 2 2 -0.7082583
> 4 3 3  0.0095178
> 5 4 4 -1.8571443
>
> I can't find a combinations of options for merge that does this. Is there
> another fonction that would do that or do I have to resort to some
> post-processing after merge? It seems that it might be something like a
> "right merge" for data bases but I don't know this world at all. I would be
> happy to look into sqldf if that allows to do things like that.
>
> Thanks in advance. Sincerely,
>
> JiHO
> ---
> http://maururu.net
>
> __
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Merge data frames but prefer values in one

2009-09-10 Thread jo
Thanks for the post-processing ideas. But is there any way to do that
in one step?

On Thu, Sep 10, 2009 at 7:20 PM, Henrique Dallazuanna  wrote:
>
> Try this:
>
> xy <- merge(x, y, by = c("a","b"),all = TRUE)
> xy$c <- ifelse(rowSums(!is.na(.x <- xy[, c('c.x', 'c.y')])) > 1, .x[,1], 
> rowSums(.x, na.rm = TRUE))
> xy
>
> On Thu, Sep 10, 2009 at 12:21 PM, JiHO  wrote:

JiHO
---
http://maururu.net

__
R-help@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.


Re: [R] Merge data frames but prefer values in one

2009-09-11 Thread Henrique Dallazuanna
Maybe:

do.call(rbind, lapply(with(xy <- rbind(x, y), split(xy, list(a, b), drop =
TRUE)), tail, 1))

On Fri, Sep 11, 2009 at 3:45 AM, jo  wrote:

> Thanks for the post-processing ideas. But is there any way to do that
> in one step?
>
> On Thu, Sep 10, 2009 at 7:20 PM, Henrique Dallazuanna 
> wrote:
> >
> > Try this:
> >
> > xy <- merge(x, y, by = c("a","b"),all = TRUE)
> > xy$c <- ifelse(rowSums(!is.na(.x <- xy[, c('c.x', 'c.y')])) > 1, .x[,1],
> rowSums(.x, na.rm = TRUE))
> > xy
> >
> > On Thu, Sep 10, 2009 at 12:21 PM, JiHO  wrote:
>
> JiHO
> ---
> http://maururu.net
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Merge data frames but prefer values in on

2009-09-14 Thread JiHO

On 2009-September-11  , at 13:55 ,  wrote:


Maybe:

do.call(rbind, lapply(with(xy <- rbind(x, y), split(xy, list(a, b),  
drop = TRUE)), tail, 1))


On Fri, Sep 11, 2009 at 3:45 AM, jo  wrote:
Thanks for the post-processing ideas. But is there any way to do that
in one step?


Thanks but by "in one step" I meant within the merge, not in one post- 
processing step ;)


JiHO
---
http://maururu.net

__
R-help@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.


Re: [R] Merge data frames but prefer values in on

2009-09-14 Thread Nandi
No you cannot. You may want to write a merge function with the special
capability but there is no better way than the one suggested by
Henrique.

On Sep 14, 12:18 pm, JiHO  wrote:
> On 2009-September-11  , at 13:55 ,  wrote:
>
> > Maybe:
>
> > do.call(rbind, lapply(with(xy <- rbind(x, y), split(xy, list(a, b),  
> > drop = TRUE)), tail, 1))
>
> > On Fri, Sep 11, 2009 at 3:45 AM, jo  wrote:
> > Thanks for the post-processing ideas. But is there any way to do that
> > in one step?
>
> Thanks but by "in one step" I meant within the merge, not in one post-
> processing step ;)
>
> JiHO
> ---http://maururu.net
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.


[R] merge data frames with same column names of different lengths and missing values

2009-03-06 Thread Steven Lubitz

Hello, I'm switching over from SAS to R and am having trouble merging data 
frames. The data frames have several columns with the same name, and each has a 
different number of rows. Some of the values are missing from cells with the 
same column names in each data frame. I had hoped that when I merged the 
dataframes, every column with the same name would be merged, with the value in 
a complete cell overwriting the value in an empty cell from the other data 
frame. I cannot seem to achieve this result, though I've tried several merge 
adaptations:

x <- data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), id=1:5)
y <- data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6)


merge(x,y,by="id") #I lose observations here (n=1 in this example), and my 
items are duplicated - I do not want this result
  id item1.x item2.x item1.y item2.y
1  1  NA   1  NA  NA
2  2  NA  NA   2  NA
3  3   3  NA  NA   3
4  4   4   4   4   4
5  5   5   5   5   5


merge(x,y,by=c("id","item1","item2")) #again I lose observations (n=4 here) and 
do not want this result
  id item1 item2
1  4 4 4
2  5 5 5


merge(x,y,by=c("id","item1","item2"),all.x=T,all.y=T) #my rows are duplicated 
and the NA values are retained - I instead want one row per ID
  id item1 item2
1  1NA 1
2  1NANA
3  2 2NA
4  2NANA
5  3 3NA
6  3NA 3
7  4 4 4
8  5 5 5
9  6 6NA

In reality I have multiple data frames with numerous columns, all with this 
problem. I can do the merge seamlessly in SAS, but am trying to learn and stick 
with R for my analyses. Any help would be greatly appreciated.

Steve Lubitz
Cardiovascular Research Fellow, Brigham and Women's Hospital and Massachusetts 
General Hospital

__
R-help@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.


Re: [R] merge data frames with same column names of different lengths and missing values

2009-03-07 Thread Domenico Vistocco

Steven Lubitz wrote:

Hello, I'm switching over from SAS to R and am having trouble merging data 
frames. The data frames have several columns with the same name, and each has a 
different number of rows. Some of the values are missing from cells with the 
same column names in each data frame. I had hoped that when I merged the 
dataframes, every column with the same name would be merged, with the value in 
a complete cell overwriting the value in an empty cell from the other data 
frame. I cannot seem to achieve this result, though I've tried several merge 
adaptations:

x <- data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), id=1:5)
y <- data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6)


merge(x,y,by="id") #I lose observations here (n=1 in this example), and my 
items are duplicated - I do not want this result
  id item1.x item2.x item1.y item2.y
1  1  NA   1  NA  NA
2  2  NA  NA   2  NA
3  3   3  NA  NA   3
4  4   4   4   4   4
5  5   5   5   5   5


merge(x,y,by=c("id","item1","item2")) #again I lose observations (n=4 here) and 
do not want this result
  id item1 item2
1  4 4 4
2  5 5 5


merge(x,y,by=c("id","item1","item2"),all.x=T,all.y=T) #my rows are duplicated 
and the NA values are retained - I instead want one row per ID
  id item1 item2
1  1NA 1
2  1NANA
3  2 2NA
4  2NANA
5  3 3NA
6  3NA 3
7  4 4 4
8  5 5 5
9  6 6NA
  

You should obtain the desired solution using:
merge(y, x, by=c("id","item1","item2"), all=TRUE)

In database terminology all=TRUE corresponds to the full outer join, 
all.x to the left outer join and all.y to the right outer join.


Ciao,
domenico


In reality I have multiple data frames with numerous columns, all with this 
problem. I can do the merge seamlessly in SAS, but am trying to learn and stick 
with R for my analyses. Any help would be greatly appreciated.

Steve Lubitz
Cardiovascular Research Fellow, Brigham and Women's Hospital and Massachusetts 
General Hospital

__
R-help@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.




__
R-help@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.


Re: [R] merge data frames with same column names of different lengths and missing values

2009-03-07 Thread Jun Shen
Steve,

I don't know if R has such a function to perform the task you were asking. I
wrote one myself. Try the following to see if it works for you. The new
function "merge.new" has one additional argument col.ID, which is the column
number of ID column. To use your x, y as examples, type:

merge.new(x,y,all=TRUE,col.ID=3)

#

merge.new<-function(...,col.ID){
inter<-merge(...)
inter<-inter[order(inter[col.ID]),] #merged data sorted by ID

#total columns and rows for the target dataframe
total.row<-length(unique(inter[[col.ID]]))
total.col<-dim(inter)[2]
row.ID<-unique(inter[[col.ID]])
target<-matrix(NA,total.row,total.col)
target<-as.data.frame(target)
names(target)<-names(inter)

for (i in 1:total.row){
inter.part<-inter[inter[col.ID]==row.ID[i],] #select all rows with
the same ID
for (j in 1:total.col){
if (is.na(inter.part[1,j])){
if(is.na(inter.part[2,j])) {target[i,j]=NA}
else {target[i,j]=inter.part[2,j]}
}
else {target[i,j]=inter.part[1,j]}

}
}
print(paste("total rows=",total.row))
print(paste("total columns=",total.col))
return(target)
}
#
-- 
Jun Shen PhD
PK/PD Scientist
BioPharma Services
Millipore Corporation
15 Research Park Dr.
St Charles, MO 63304
Direct: 636-720-1589

On Fri, Mar 6, 2009 at 11:02 PM, Steven Lubitz  wrote:

>
> Hello, I'm switching over from SAS to R and am having trouble merging data
> frames. The data frames have several columns with the same name, and each
> has a different number of rows. Some of the values are missing from cells
> with the same column names in each data frame. I had hoped that when I
> merged the dataframes, every column with the same name would be merged, with
> the value in a complete cell overwriting the value in an empty cell from the
> other data frame. I cannot seem to achieve this result, though I've tried
> several merge adaptations:
>
> x <- data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), id=1:5)
> y <- data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6)
>
>
> merge(x,y,by="id") #I lose observations here (n=1 in this example), and my
> items are duplicated - I do not want this result
>  id item1.x item2.x item1.y item2.y
> 1  1  NA   1  NA  NA
> 2  2  NA  NA   2  NA
> 3  3   3  NA  NA   3
> 4  4   4   4   4   4
> 5  5   5   5   5   5
>
>
> merge(x,y,by=c("id","item1","item2")) #again I lose observations (n=4 here)
> and do not want this result
>  id item1 item2
> 1  4 4 4
> 2  5 5 5
>
>
> merge(x,y,by=c("id","item1","item2"),all.x=T,all.y=T) #my rows are
> duplicated and the NA values are retained - I instead want one row per ID
>  id item1 item2
> 1  1NA 1
> 2  1NANA
> 3  2 2NA
> 4  2NANA
> 5  3 3NA
> 6  3NA 3
> 7  4 4 4
> 8  5 5 5
> 9  6 6NA
>
> In reality I have multiple data frames with numerous columns, all with this
> problem. I can do the merge seamlessly in SAS, but am trying to learn and
> stick with R for my analyses. Any help would be greatly appreciated.
>
> Steve Lubitz
> Cardiovascular Research Fellow, Brigham and Women's Hospital and
> Massachusetts General Hospital
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] merge data frames with same column names of different lengths and missing values

2009-03-07 Thread Steven Lubitz
Subject: Re: [R] merge data frames with same column names of different lengths 
and missing values
To: "Phil Spector" 
Date: Saturday, March 7, 2009, 5:01 PM

Phil,
Thank you - this is very helpful. However I realized that with my real data 
sets (not the example I have here), I also have different numbers of columns in 
each data frame. rbind doesn't seem to like this. Here's a modified example:

x <- data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), 
item3=c(NA,2,NA,4,NA), id=1:5)
y <- data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6)

rbind(x,y)
Error in rbind(deparse.level, ...) : 
  numbers of columns of arguments do not match

Any ideas?
Thanks,
Steve


--- On Sat, 3/7/09, Phil Spector  wrote:
From: Phil Spector 
Subject: Re: [R] merge data frames with
 same column names of different lengths and missing values
To: "Steven Lubitz" 
Date: Saturday, March 7, 2009, 1:56 AM

Steven -
  I believe this gives the output that you desire:

> xy = rbind(x,y)
>
aggregate(subset(xy,select=-id),xy['id'],function(x)rev(x[!is.na(x)])[1])
   id item1 item2
1  1NA 1
2  2 2NA
3  3 3 3
4  4 4 4
5  5 5 5
6  6 6NA

  But I think what merge x y; by id; would give you is

> aggregate(subset(xy,select=-id),xy['id'],function(x)x[length(x)])
   id item1 item2
1  1NANA
2  2 2NA
3  3NA 3
4  4 4 4
5  5 5 5
6  6 6NA

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley

 spec...@stat.berkeley.edu





On Fri, 6 Mar 2009, Steven Lubitz wrote:

>
> Hello, I'm switching over from SAS to R and am having trouble merging
data frames. The data frames have several columns with the same name, and each
has a different number of rows. Some of the values are missing from cells with
the same column names in each data frame. I had hoped that when I merged the
dataframes, every column with the same name would be merged, with the value in a
complete cell overwriting the value in an empty cell from the other data frame.
I cannot seem to achieve this result, though I've tried several merge
adaptations:
>
> x <- data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), id=1:5)
> y <- data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA),
id=1:6)
>
>
> merge(x,y,by="id") #I lose observations here (n=1 in this
example), and my items are
 duplicated - I do not want this result
>  id item1.x item2.x item1.y item2.y
> 1  1  NA   1  NA  NA
> 2  2  NA  NA   2  NA
> 3  3   3  NA  NA   3
> 4  4   4   4   4   4
> 5  5   5   5   5   5
>
>
> merge(x,y,by=c("id","item1","item2")) #again
I lose observations (n=4 here) and do not want this result
>  id item1 item2
> 1  4 4 4
> 2  5 5 5
>
>
>
merge(x,y,by=c("id","item1","item2"),all.x=T,all.y=T)
#my rows are duplicated and the NA values are retained - I instead want one row
per ID
>  id item1 item2
> 1  1NA 1
> 2  1NANA
> 3  2 2NA
> 4  2NANA
> 5  3 3NA
> 6  3NA 3
> 7  4 4 4
> 8  5 5 5
> 9  6 6NA
>
> In reality I
 have multiple data frames with numerous columns, all with
this problem. I can do the merge seamlessly in SAS, but am trying to learn and
stick with R for my analyses. Any help would be greatly appreciated.
>
> Steve Lubitz
> Cardiovascular Research Fellow, Brigham and Women's Hospital and
Massachusetts General Hospital
>
> __
> R-help@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.
>



  


  
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] merge data frames with same column names of differe nt lengths and missing values

2009-03-07 Thread Dieter Menne
Steven Lubitz  yahoo.com> writes:

> 
> x <- data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), id=1:5)
> y <- data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6)
> 

> merge(x,y,by=c("id","item1","item2"),all.x=T,all.y=T) #my rows are duplicated
and the NA values are
> retained - I instead want one row per ID
>   id item1 item2
> 1  1NA 1
> 2  1NANA
> 3  2 2NA
> 4  2NANA
> 5  3 3NA
> 6  3NA 3
> 7  4 4 4
> 8  5 5 5
> 9  6 6NA
> 
I think you only got the wrong (too complex) function. Try rbind(x,y)

Dieter

__
R-help@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.


Re: [R] merge data frames with same column names of differe nt lengths and missing values

2009-03-08 Thread Dieter Menne
Steven Lubitz  yahoo.com> writes:

> Thank you - this is very helpful. However I realized that with my real data
sets (not the example I have here),
> I also have different numbers of columns in each data frame. rbind doesn't
seem to like this. Here's a
> modified example:
> 
> x <- data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5),
item3=c(NA,2,NA,4,NA), id=1:5)
> y <- data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6)
> 
> rbind(x,y)

You should add dummy  variables to each partial data frame
such that they look the same, and do the rbind later.

Dieter

__
R-help@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.


[R] Merge 10 data frames with 3 id columns that are common to all data frames

2009-03-08 Thread Pele

Hi R users,

Can anyone share some example code using merge_all (from the reshape
package) to merge 10 data frames into 1 file.

Thanks in advance for any help!
-- 
View this message in context: 
http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames

2009-03-08 Thread baptiste auguie

Hi,

Try this:


DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
DF2 <- data.frame(var1 = letters[3:7], x = rnorm(5), y=3)
DF3 <- data.frame(var1 = letters[6:10], x = rnorm(5), y=0)
 # ... DF10 if you wish

( result <- merge_all(list(DF1, DF2, DF3) ))

save( result, file ="merged.rda")


I didn't know of this function, thanks. Similar solutions using base  
functions were proposed recently on http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge 
 and i've now added this for reference.


baptiste

On 8 Mar 2009, at 20:23, Pele wrote:



Hi R users,

Can anyone share some example code using merge_all (from the reshape
package) to merge 10 data frames into 1 file.

Thanks in advance for any help!
--
View this message in context: 
http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
R-help@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.


Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames

2009-03-08 Thread Pele

I tried using merge_all as shown below but I am getting an error ... can
anyone tell me what I am doing wrong?  The result table below is what I am
looking for.

DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
DF2 <- data.frame(var1 = letters[1:5], t = rnorm(5), u =2)
DF3 <- data.frame(var1 = letters[1:5], d = rnorm(5), e =31)
DF4 <- data.frame(var1 = letters[1:5], f = rnorm(5), o =11)

DF_all <- merge_all(DF1, DF2, DF3, DF4, by="var1" )

Error in fix.by(by.x, x) : 
  'by' must specify column(s) as numbers, names or logical

Results I would like
var1x   y   d   e   t   u   
x   
a   -1.725155   2   -0.4809731  0.0329682   
-1.725155   
b   0.7999832   2.32965 31  -0.385364   2   
0.799983
c   -1.387224   2   0.61761 31  0.9774042   
-1.387224   
d   0.6459462   0.46152 31  1.3345912   
0.645946
e   0.0587832   -0.2531231  0.6316762   
0.058783






baptiste auguie-2 wrote:
> 
> Hi,
> 
> Try this:
> 
>> DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
>> DF2 <- data.frame(var1 = letters[3:7], x = rnorm(5), y=3)
>> DF3 <- data.frame(var1 = letters[6:10], x = rnorm(5), y=0)
>>  # ... DF10 if you wish
>>
>> ( result <- merge_all(list(DF1, DF2, DF3) ))
>>
>> save( result, file ="merged.rda")
> 
> I didn't know of this function, thanks. Similar solutions using base  
> functions were proposed recently on
> http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge 
>   and i've now added this for reference.
> 
> baptiste
> 
> On 8 Mar 2009, at 20:23, Pele wrote:
> 
>>
>> Hi R users,
>>
>> Can anyone share some example code using merge_all (from the reshape
>> package) to merge 10 data frames into 1 file.
>>
>> Thanks in advance for any help!
>> --
>> View this message in context:
>> http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@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.
> 
> _
> 
> Baptiste Auguié
> 
> School of Physics
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
> 
> Phone: +44 1392 264187
> 
> http://newton.ex.ac.uk/research/emag
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22404595.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames

2009-03-08 Thread baptiste auguie
The function expects a list of data.frames as a first argument but you  
provided a data.frame instead, the others are interpreted as optional  
arguments to merge_recurse(). Try this instead,



merge_recurse(list(DF1,DF2,DF3,DF4))



  var1x yt u d  ef  o
1a  1.39679 2 -1.18377 2 -0.041194 31 -1.05526 11
2b -0.20453 2  0.22777 2 -0.543270 31  1.45777 11
3c -0.91446 2 -0.97843 2 -1.279132 31  1.88759 11
4d -1.18069 2 -0.23963 2 -0.064799 31 -0.85747 11
5e -1.24802 2  1.43072 2  0.183317 31  2.50352 11


HTH,

baptiste

On 8 Mar 2009, at 23:40, Pele wrote:



I tried using merge_all as shown below but I am getting an error ...  
can
anyone tell me what I am doing wrong?  The result table below is  
what I am

looking for.

DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
DF2 <- data.frame(var1 = letters[1:5], t = rnorm(5), u =2)
DF3 <- data.frame(var1 = letters[1:5], d = rnorm(5), e =31)
DF4 <- data.frame(var1 = letters[1:5], f = rnorm(5), o =11)

DF_all <- merge_all(DF1, DF2, DF3, DF4, by="var1" )

Error in fix.by(by.x, x) :
 'by' must specify column(s) as numbers, names or logical

Results I would like
var1x   y   d   e
t   u   x
a   -1.725155   2   -0.4809731   
0.0329682   -1.725155
b   0.7999832   2.32965 31   
-0.385364   2   0.799983
c   -1.387224   2   0.61761 31   
0.9774042   -1.387224
d   0.6459462   0.46152 31   
1.3345912   0.645946
e   0.0587832   -0.2531231   
0.6316762   0.058783







baptiste auguie-2 wrote:


Hi,

Try this:


DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
DF2 <- data.frame(var1 = letters[3:7], x = rnorm(5), y=3)
DF3 <- data.frame(var1 = letters[6:10], x = rnorm(5), y=0)
# ... DF10 if you wish

( result <- merge_all(list(DF1, DF2, DF3) ))

save( result, file ="merged.rda")


I didn't know of this function, thanks. Similar solutions using base
functions were proposed recently on
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge
 and i've now added this for reference.

baptiste

On 8 Mar 2009, at 20:23, Pele wrote:



Hi R users,

Can anyone share some example code using merge_all (from the reshape
package) to merge 10 data frames into 1 file.

Thanks in advance for any help!
--
View this message in context:
http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
R-help@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.




--
View this message in context: 
http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22404595.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
R-help@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.


Re: [R] Merge 10 data frames with 3 id columns that are common to all data frames

2009-03-08 Thread Pele

Perfect - many thanks!!!


baptiste auguie-2 wrote:
> 
> The function expects a list of data.frames as a first argument but you  
> provided a data.frame instead, the others are interpreted as optional  
> arguments to merge_recurse(). Try this instead,
> 
>> merge_recurse(list(DF1,DF2,DF3,DF4))
> 
> 
>var1x yt u d  ef  o
> 1a  1.39679 2 -1.18377 2 -0.041194 31 -1.05526 11
> 2b -0.20453 2  0.22777 2 -0.543270 31  1.45777 11
> 3c -0.91446 2 -0.97843 2 -1.279132 31  1.88759 11
> 4d -1.18069 2 -0.23963 2 -0.064799 31 -0.85747 11
> 5e -1.24802 2  1.43072 2  0.183317 31  2.50352 11
> 
> 
> HTH,
> 
> baptiste
> 
> On 8 Mar 2009, at 23:40, Pele wrote:
> 
>>
>> I tried using merge_all as shown below but I am getting an error ...  
>> can
>> anyone tell me what I am doing wrong?  The result table below is  
>> what I am
>> looking for.
>>
>> DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
>> DF2 <- data.frame(var1 = letters[1:5], t = rnorm(5), u =2)
>> DF3 <- data.frame(var1 = letters[1:5], d = rnorm(5), e =31)
>> DF4 <- data.frame(var1 = letters[1:5], f = rnorm(5), o =11)
>>
>> DF_all <- merge_all(DF1, DF2, DF3, DF4, by="var1" )
>>
>> Error in fix.by(by.x, x) :
>>  'by' must specify column(s) as numbers, names or logical
>>
>> Results I would like
>> var1x   y   d   e
>> t   u   x
>> a   -1.725155   2   -0.4809731   
>> 0.0329682   -1.725155
>> b   0.7999832   2.32965 31   
>> -0.385364   2   0.799983
>> c   -1.387224   2   0.61761 31   
>> 0.9774042   -1.387224
>> d   0.6459462   0.46152 31   
>> 1.3345912   0.645946
>> e   0.0587832   -0.2531231   
>> 0.6316762   0.058783
>>
>>
>>
>>
>>
>>
>> baptiste auguie-2 wrote:
>>>
>>> Hi,
>>>
>>> Try this:
>>>
 DF1 <- data.frame(var1 = letters[1:5], x = rnorm(5), y =2)
 DF2 <- data.frame(var1 = letters[3:7], x = rnorm(5), y=3)
 DF3 <- data.frame(var1 = letters[6:10], x = rnorm(5), y=0)
 # ... DF10 if you wish

 ( result <- merge_all(list(DF1, DF2, DF3) ))

 save( result, file ="merged.rda")
>>>
>>> I didn't know of this function, thanks. Similar solutions using base
>>> functions were proposed recently on
>>> http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge
>>>  and i've now added this for reference.
>>>
>>> baptiste
>>>
>>> On 8 Mar 2009, at 20:23, Pele wrote:
>>>

 Hi R users,

 Can anyone share some example code using merge_all (from the reshape
 package) to merge 10 data frames into 1 file.

 Thanks in advance for any help!
 --
 View this message in context:
 http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22402493.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.
>>>
>>> _
>>>
>>> Baptiste Auguié
>>>
>>> School of Physics
>>> University of Exeter
>>> Stocker Road,
>>> Exeter, Devon,
>>> EX4 4QL, UK
>>>
>>> Phone: +44 1392 264187
>>>
>>> http://newton.ex.ac.uk/research/emag
>>>
>>> __
>>> R-help@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.
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Merge-10-data-frames-with-3-id-columns-that-are-common-to-all-data-frames-tp22402493p22404595.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@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.
> 
> _
> 
> Baptiste Auguié
> 
> School of Physics
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
> 
> Phone: +44 1392 264187
> 
> http://newton.ex.ac.uk/research/emag
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Merge-10-data-frames-with-3-id-colu