Re: [R] R-Help

From: john seers (IFR) <john.seers_at_bbsrc.ac.uk>
Date: Thu 20 Apr 2006 - 23:25:08 EST

I think this does what you require.

#Read your data in whatever way you wish:

d1<-data.frame(Date=c("2005/1/1","2005/2/1","2005/1/3","2005/1/4","2005/ 1/7","2005/3/5"),

		x=c(119,123,-110,114,11,200),
		y=c(230,-125,300,-21,299,311))

d2<-data.frame(Date=c("2005/1/3","2005/1/4","2005/1/5","2005/1/6","2005/ 3/5"),

		x=c(-220,116,888,-239,201),
		y=c(301,-23,3000,122,312))


d3<-data.frame(Date=c("2005/1/4","2005/1/5","2005/3/5","2005/4/23"),
		x=c(392,511,600,723),
		y=c(-81,6699,9311,1200))


#Make a list

listof<-list(d1,d2,d3)

#loop over any number of datasets merging as you go

for ( dataset in 1:length(listof)-1) {

        if (dataset == 1) {         

res<-merge(listof[dataset],listof[dataset+1],all=T,by="Date")

	} else {
		res<-merge(res,listof[dataset+1],all=T,by="Date")	
	}

}

# Hope that helps

JS  

---

John Seers
Institute of Food Research
Norwich Research Park
Colney
Norwich
NR4 7UA
 

tel +44 (0)1603 251490 
fax +44 (0)1603 255167
e-mail john.seers@bbsrc.ac.uk                         
e-disclaimer at http://www.ifr.ac.uk/edisclaimer/ 
 
Web sites:

www.ifr.ac.uk   
www.foodandhealthnetwork.com


-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of stat stat
Sent: 20 April 2006 09:17
To: r-help@stat.math.ethz.ch
Subject: [R] R-Help


Dear r-users,
  
Suppose I have three datasets:
  Dataset-1:
  Date              x         y
  Jan-1,2005    120       230
Jan-2,2005    123       -125
Jan-3,2005    -110      300
Jan-4,2005    114       -21
Jan-7,2005    11        299
Mar-5,2005    200       311
   
  Dataset-2:
  Date              x          y
  Jan-2,2005    123       -125
Jan-3,2005    -110      300
Jan-4,2005    114       -21
Jan-5,2005    11        299
Jan-6,2005    -23       12
Mar-5,2005    200       311
   
  Dataset-3:
  Date              x          y
  Jan-3,2005    -110      300
Jan-4,2005    114       -21
Jan-5,2005    11        299
Mar-5,2005    200       311
Apl-23,2005   123       200
  Now I want to get the common dates along with x and y from this above
three datasets keeping the same order
in date-variable as it is.
  For ex. I want to get:
  Date            x          y                 x            y
x          y
               (from dataset-1)         (from dataset-2)          (from
dataset-3)
------------------------------------------------------------------------
------------------------
  Jan-3,2005    -110      300          -110         300
-110      300
Jan-4,2005     114      -21             114        -21               114
-21
Mar-5,2005    200       311           200         311              200
311
  Can anyone give me any R code to implement this for any number of
datasets ?
  Thanks and regards


thanks in advance
				
---------------------------------


	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Apr 20 23:30:03 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 21 Apr 2006 - 00:10:00 EST.

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