[R] help with two layers of factors

David Winsemius dwinsemius at comcast.net
Fri Apr 3 03:45:57 CEST 2009


 > df <- read.table(textConnection('Experiment_id Treament_type Value
+ 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:

>
> 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!
> -- 
> View this message in context: http://www.nabble.com/help-with-two-layers-of-factors-tp22851129p22851129.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list