Re: [R] merge question

2014-06-30 Thread Dr Eberhard W Lisse
Rolf,

I hear you. 

But, after reflection, ie I looked at my situation again, it is great :-)-O

el


Sent from Dr Lisse's iPad mini

> On Jun 30, 2014, at 0:48, Rolf Turner  wrote:
> 
> 
>> On 30/06/14 10:32, Dr Eberhard W Lisse wrote:
>> 
>> Thanks,
>> 
>> I then set NA to 0, and can do the sutraction,
>> 
>> great.
> 
> Not so great.  I haven't gone through the issues underlying this post, but 
> replacing NA by 0 will almost surely yield nonsense.  "Missing" is ***not*** 
> the same thing as "zero".  Pretending that it is will have disastrous 
> consequences.  Think through what you are trying to do more clearly.
> 
> cheers,
> 
> Rolf Turner

__
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

2014-06-29 Thread Dr Eberhard W Lisse
Thank you very much.

el

On 2014-06-30, 00:48 , Rolf Turner wrote:
> 
> On 30/06/14 10:32, Dr Eberhard W Lisse wrote:
> 
>> Thanks,
>>
>> I then set NA to 0, and can do the sutraction,
>>
>> great.
> 
> Not so great.  I haven't gone through the issues underlying this post,
> but replacing NA by 0 will almost surely yield nonsense.  "Missing" is
> ***not*** the same thing as "zero".  Pretending that it is will have
> disastrous consequences.  Think through what you are trying to do more
> clearly.
> 
> cheers,
> 
> Rolf Turner

__
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

2014-06-29 Thread Rolf Turner


On 30/06/14 10:32, Dr Eberhard W Lisse wrote:


Thanks,

I then set NA to 0, and can do the sutraction,

great.


Not so great.  I haven't gone through the issues underlying this post, 
but replacing NA by 0 will almost surely yield nonsense.  "Missing" is 
***not*** the same thing as "zero".  Pretending that it is will have 
disastrous consequences.  Think through what you are trying to do more 
clearly.


cheers,

Rolf Turner

__
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

2014-06-29 Thread Dr Eberhard W Lisse
Thanks,

I then set NA to 0, and can do the sutraction,

great.

el


On 2014-06-29, 22:32 , Michael Peng wrote:
> you can get a new data frame by
> merge(qpiso, qplegit, all.x = TRUE, all.y = TRUE, by = "iso" )
> Take the subtraction on the new data frame.
> 
> 
> 
> 
> 2014-06-29 11:24 GMT-05:00 Dr Eberhard Lisse  >:
> 
> I have two data frames like so
> 
> > qpiso
> iso requests
> 1A1   20
> 2A2  199
> 3AD5
> 4AE  176
> ...
> 189  ZW   82
> 
> > qplegit
> iso requests
> 1A2   36
> 2AE4
> 3AM2
> 4AO1
> ...
> 100  ZW3
> 
> 
> I want to create another dataframe qpspam which contains all pairs
> from pqiso with the values for requests of qplegit being subtracted
> from those which exist in qpiso,
> 
> ie
> iso requests
> 1A1   20
> 2A2  163
> 3AD5
> 4AE  172
> ...
> 189  ZW   79
> 
> but don't know how to do this, and google isn't too helpful.
> 
> As usual, a solution is preferred, but a pointer to where I can
> read this up is equally appreciated :-)-O
> 
> el
> 
> __
> 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 question

2014-06-29 Thread Michael Peng
you can get a new data frame by
merge(qpiso, qplegit, all.x = TRUE, all.y = TRUE, by = "iso" )
Take the subtraction on the new data frame.




2014-06-29 11:24 GMT-05:00 Dr Eberhard Lisse :

> I have two data frames like so
>
> > qpiso
> iso requests
> 1A1   20
> 2A2  199
> 3AD5
> 4AE  176
> ...
> 189  ZW   82
>
> > qplegit
> iso requests
> 1A2   36
> 2AE4
> 3AM2
> 4AO1
> ...
> 100  ZW3
>
>
> I want to create another dataframe qpspam which contains all pairs
> from pqiso with the values for requests of qplegit being subtracted
> from those which exist in qpiso,
>
> ie
> iso requests
> 1A1   20
> 2A2  163
> 3AD5
> 4AE  172
> ...
> 189  ZW   79
>
> but don't know how to do this, and google isn't too helpful.
>
> As usual, a solution is preferred, but a pointer to where I can
> read this up is equally appreciated :-)-O
>
> el
>
> __
> 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

2014-06-29 Thread Jeff Newmiller
If you really prefer solution code, then provide reproducible example code as 
the footer requests.

Use ?merge with the all.x=TRUE parameter, and then perform your calculations on 
the resulting combined data frame, using ?ifelse and ?is.na as needed.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On June 29, 2014 9:24:39 AM PDT, Dr Eberhard Lisse  wrote:
>I have two data frames like so
>
>> qpiso
>iso requests
>1A1   20
>2A2  199
>3AD5
>4AE  176
>...
>189  ZW   82
>
>> qplegit
>iso requests
>1A2   36
>2AE4
>3AM2
>4AO1
>...
>100  ZW3
>
>
>I want to create another dataframe qpspam which contains all pairs
>from pqiso with the values for requests of qplegit being subtracted
>from those which exist in qpiso,
>
>ie
>iso requests
>1A1   20
>2A2  163
>3AD5
>4AE  172
>...
>189  ZW   79
>
>but don't know how to do this, and google isn't too helpful.
>
>As usual, a solution is preferred, but a pointer to where I can
>read this up is equally appreciated :-)-O
>
>el
>
>__
>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 question

2014-06-29 Thread Dr Eberhard Lisse
I have two data frames like so

> qpiso
iso requests
1A1   20
2A2  199
3AD5
4AE  176
...
189  ZW   82

> qplegit
iso requests
1A2   36
2AE4
3AM2
4AO1
...
100  ZW3


I want to create another dataframe qpspam which contains all pairs
from pqiso with the values for requests of qplegit being subtracted
from those which exist in qpiso,

ie
iso requests
1A1   20
2A2  163
3AD5
4AE  172
...
189  ZW   79

but don't know how to do this, and google isn't too helpful.

As usual, a solution is preferred, but a pointer to where I can
read this up is equally appreciated :-)-O

el

__
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 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.


[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.