R: What are the best functions to deal with concatenating and averaging values in a data.frame?

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-18T22:06:29Z Indexed on 2010/03/18 22:21 UTC
Read the original article Hit count: 180

Filed under:
|
|
|

I have a data.frame from this code:

   my_df = data.frame("read_time" = c("2010-02-15", "2010-02-15", 
                                      "2010-02-16", "2010-02-16", 
                                       "2010-02-16", "2010-02-17"), 
                      "OD" = c(0.1, 0.2, 0.1, 0.2, 0.4, 0.5) )

which produces this:

> my_df
   read_time  OD
1 2010-02-15 0.1
2 2010-02-15 0.2
3 2010-02-16 0.1
4 2010-02-16 0.2
5 2010-02-16 0.4
6 2010-02-17 0.5

I want to average the OD column over each distinct read_time (notice some are replicated others are not) and I also would like to calculate the standard deviation, producing a table like this:

> my_df
   read_time  OD        stdev
1 2010-02-15 0.15       0.05
5 2010-02-16 0.3         0.1
6 2010-02-17 0.5         0

Which are the best functions to deal with concatenating such values in a data.frame?

© Stack Overflow or respective owner

Related posts about r

    Related posts about concatenate