[R] Joining uneven datasets

From: Neil Gupta <neil.gup_at_gmail.com>
Date: Thu, 29 May 2008 09:40:13 -0500


Hello,

I have quite a simple problem that I believe can be solved quite easily. I have a dataframe as such:

Symbol       Date     Time Exchange TickType ReferenceNumber Price Size
1 3:YMZ7.EC 12/03/2007 08:30:00       EC        B        83916044 13387    9
2 3:YMZ7.EC 12/03/2007 08:30:00       EC        A        83916045 13388    1
3 3:YMZ7.EC 12/03/2007 08:30:00       EC        B        83916054 13387    9
4 3:YMZ7.EC 12/03/2007 08:30:00       EC        A        83916055 13388    1
5 3:YMZ7.EC 12/03/2007 08:30:00       EC        B        83916533 13386   39
6 3:YMZ7.EC 12/03/2007 08:30:00       EC        A        83916534 13388    1

I wanted the average of the B's and A's. I wrote this to perform that.  NPrice <-
(YM1207$Price[which(YM1207$TickType=="B")]+YM1207$Price[which(YM1207$TickType=="A")])/2

head(NPrice)
[1] 13387.5 13387.5 13387.0 13386.5 13386.5 13387.0

Now since NPrice is much smaller than the original dataframe, YM1207 I can not just add NPrice to the set.
How can I put each of those averages back into their corresponding row? I would even prefer repeating the values for A's as well..

I would like to do it as such..

Symbol Date Time Exchange TickType ReferenceNumber Price Size NPrice
1 3:YMZ7.EC 12/03/2007 08:30:00 EC B 83916044 13387 9 13387.5
2 3:YMZ7.EC 12/03/2007 08:30:00 EC A 83916045 13388 1 13387.5
3 3:YMZ7.EC 12/03/2007 08:30:00 EC B 83916054 13387 9 13387.5

4 3:YMZ7.EC 12/03/2007 08:30:00       EC        A        83916055 13388
1     13387.5
5 3:YMZ7.EC 12/03/2007 08:30:00       EC        B        83916533 13386
39   13387.0
6 3:YMZ7.EC 12/03/2007 08:30:00       EC        A        83916534 13388
1 13387.0

Thankyou much

Neil

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 29 May 2008 - 16:13:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 29 May 2008 - 17:30:45 GMT.

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

list of date sections of archive