merge() can align the values in the obs columns so those with the same date can be compared. E.g., set up the data with the following copy-and-pastable code:
A <- read.table(header=TRUE, textConnection(" year mon day obs 2010 03 12 12 2010 03 18 22 2010 04 12 62 2010 07 24 29 ")) B <- read.table(header=TRUE, textConnection("year mon day obs 2010 03 12 15 2010 04 12 57 2010 07 24 32 2010 08 23 15 ")) AB <- merge(A, B, by=c("year", "mon", "day"), suffixes=c("A","B")) and you can use AB to do comparisons: > AB year mon day obsA obsB 1 2010 3 12 12 15 2 2010 4 12 62 57 3 2010 7 24 29 32 > with(AB, obsA - obsB) [1] -3 5 -3 Look at help("merge") for more options. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Jie TANG > Sent: Wednesday, August 24, 2011 6:57 PM > To: Jeff Newmiller; r-help@r-project.org > Subject: Re: [R] how to compare two dataset with same sampling > > thanks. > Merge? I am just looking for a method to comparison on homogeneous sample > between two dataset. > > > 2011/8/25 Jeff Newmiller <jdnew...@dcn.davis.ca.us> > > > ?merge may be what you are looking for. If not, you should clarify what you > > want to do. > > --------------------------------------------------------------------------- > > Jeff Newmiller The ..... ..... Go Live... > > DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... > > Live: OO#.. Dead: OO#.. Playing > > Research Engineer (Solar/Batteries O.O#. #.O#. with > > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > > --------------------------------------------------------------------------- > > > > Sent from my phone. Please excuse my brevity. > > > > Jie TANG <totang...@gmail.com> wrote: > > > >> hi , > >> Now I have two dataset and want to compare them with same sample. > >> Dataset A: > >> year mon day obs > >> 2010 03 12 12 > >> 2010 03 18 22 > >> 2010 04 12 62 > >> 2010 07 24 29 > >> > >> Dataset B: > >> year mon day obs > >> 2010 03 12 15 > >> 2010 04 12 57 > >> 2010 07 24 32 > >> 2010 08 23 15 > >> > >> > >> As you see,dataset A and B have several observation data but their obs data > >> is not same everyday. > >> Now I want to compare the data from two dataset in the same time. > >> How could I write the R script? > >> > >> errdata<-subset(A,A$V11==Bdata$V11 & A$V12==B$V12) > >> > >> this command seems failed.How could I? > >> > >> -- > >> > >> [[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. > >> > >> > > > -- > TANG Jie > Email: totang...@gmail.com > > [[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-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.