[R] merge data frames taking mean/mode of multiple macthes

2005-01-17 Thread avneet singh
Hello :)

I have two data frames, one has properties taken on a
piece by piece basis and the other has performance on
a lot by lot basis. I wish to combine these two data
frames but the problem is that each lot has multiple
pieces and hence i need to take a mean of the
properties of multiple pieces and match it to the row
having data about the lot.

I was wondering if there is a simple commmand, an
extension of merge, or an option of merge i do not
know which could easily do this work.

Thank you  :)

=
I believe in equality for everyone, except reporters and photographers.
~Mahatma Gandhi

__
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


Re: [R] merge data frames taking mean/mode of multiple macthes

2005-01-17 Thread Christoph Buser
Dear Avneet

the function aggregate (see also ?aggregate) could be useful for
your problem. See the short example I've written below.

dat1 - data.frame(lot = factor(1:10),y1 = rnorm(10))
str(dat1)
dat2 - data.frame(nr = 1:100, lot = factor(rep(1:10, each = 10)),y2 = 
rnorm(100))
str(dat2)

dat2.agr - aggregate(dat2$y, by = list(lot = dat2$lot), FUN = mean)
names(dat2.agr)[2] - y2

dat.mer - merge(dat1, dat2.agr)
str(dat.mer)

Be careful about merging dataframes. There should always be a
control that the right cases are merged together.

Regards,

Christoph Buser

-- 
Christoph Buser [EMAIL PROTECTED]
Seminar fuer Statistik, LEO C11
ETH (Federal Inst. Technology)  8092 Zurich  SWITZERLAND
phone: x-41-1-632-5414  fax: 632-1228
http://stat.ethz.ch/~buser/


avneet singh writes:
  Hello :)
  
  I have two data frames, one has properties taken on a
  piece by piece basis and the other has performance on
  a lot by lot basis. I wish to combine these two data
  frames but the problem is that each lot has multiple
  pieces and hence i need to take a mean of the
  properties of multiple pieces and match it to the row
  having data about the lot.
  
  I was wondering if there is a simple commmand, an
  extension of merge, or an option of merge i do not
  know which could easily do this work.
  
  Thank you  :)
  
  =
  I believe in equality for everyone, except reporters and photographers.
  ~Mahatma Gandhi
  
  __
  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

-- 
Christoph Buser [EMAIL PROTECTED]
Seminar fuer Statistik, LEO C11
ETH (Federal Inst. Technology)  8092 Zurich  SWITZERLAND
phone: x-41-1-632-5414  fax: 632-1228
http://stat.ethz.ch/~buser/

__
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