Skip to content

help with two layers of factors

2 messages · haettulegur, David Winsemius

#
I have a data frame that looks something like...

Column 1 is an experiment_id, Column 2 is the type of treatment ("control",
"full treatment", or "partial treatment"), and Column 3 is a value.

Experiment_id Treament_type Value
12345    "control"    3
12345    "full treatment"    4
12345    "full treatment"    5
12345    "partial treatment"    4
10000    "control"    1

What I want to do is this:
For each experiment_id, compute the mean "control" value, the mean "full
treatment" value, and the mean "partial treatment" value.
Is there an easy way to do this?

(Also, for each experiment_id, I then want to find 
1) "mean full treatment value" - "mean control value"
2) "mean partial treatment value" - "mean control value".)

Thanks!
#
+ 12345    "control"    3
+ 12345    "full treatment"    4
+ 12345    "full treatment"    5
+ 12345    "partial treatment"    4
+ 10000    "control"    1'), header = TRUE)
 > df
   Experiment_id     Treament_type Value
1         12345           control     3
2         12345    full treatment     4
3         12345    full treatment     5
4         12345 partial treatment     4
5         10000           control     1
 > tapply(df$Value, df$Treatment_type, mean)
Error in as.vector(x, mode) : invalid 'mode' argument
# Hey, cut me some slack, I speeled treatment correctly
# Try again:

 > tapply(df$Value, df$Treament_type, mean)
           control    full treatment partial treatment
               2.0               4.5               4.0

--  
David Winsemius
On Apr 2, 2009, at 12:54 PM, haettulegur wrote:

            
David Winsemius, MD
Heritage Laboratories
West Hartford, CT