-2

Possible Duplicate:
R Grouping functions: sapply vs. lapply vs. apply. vs. tapply vs. by vs. aggregate vs.

uptake  time    treatment
2.08    0   1
2.07    0   1
2.09    0   1
2.06    0   1
2.17    1   1
2.15    1   1
2.16    1   1
2.15    1   1
2.08    0   2
2.09    0   2
2.07    0   2
2.04    0   2
2.03    1   2
2.04    1   2
2.01    1   2
2.08    1   2

My data now looks like this and we want to know the mean for each treatment in different time. For example, the mean in treatment = 1 and time = 0, etc and show up on one new variable in R. Is there any convenient code in R to do this?

Community
  • 1
  • 1
user1489975
  • 1,841
  • 2
  • 14
  • 8
  • 1
    This question has been answered many times on SO. Here is one overarching example http://stackoverflow.com/questions/3505701/ – mnel Sep 21 '12 at 02:13
  • 1
    At the same time you are going back to do self study on searching and R basics you might want to throw a few check-marks for other questions that were answered. – IRTFM Sep 21 '12 at 02:15

1 Answers1

0

@mnel is correct is the first comment -- this is close to being the mother of all FAQs here.

That said, here is a simple plyr example for you where your data is in data:

R> ddply(data, .(time, treatment), "colMeans")
  uptake time treatment
1 2.0750    0         1
2 2.0700    0         2
3 2.1575    1         1
4 2.0400    1         2
R> 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725