[R] bug in 'margins' behavior in reshape - cast

From: mfrumin <michael_at_frumin.net>
Date: Wed, 30 Jul 2008 09:47:12 -0700 (PDT)

according to the documentation of the cast function in the reshape function, I would expect this bit of code from the examples to calculate marginal means over only the 'diet' variable.

#Chick weight example
names(ChickWeight) <- tolower(names(ChickWeight)) chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE) cast(chick_m, diet + chick ~ time, mean, margins="diet")

But,
summary(cast(subset(chick_m, time == 0), diet + chick ~ time, mean, margins="diet")) returns:

    diet chick 0

 1    :21   (all)  : 4   Min.   :39.00  
 2    :11   18     : 1   1st Qu.:40.85  
 3    :11   16     : 1   Median :41.00  
 4    :11   15     : 1   Mean   :41.05  
 (all): 0   13     : 1   3rd Qu.:42.00  
            9      : 1   Max.   :43.00  
            (Other):45                  

which shows that it calculated margins on the 'chick' column as well. this behavior causes great problems for me when in my data one of the columns is a non-factor column, eg a Date, but the unrequested margining behavior turns that column into a factor.

am I missing something?

Thanks,
Mike

-- 
View this message in context: http://www.nabble.com/bug-in-%27margins%27-behavior-in-reshape---cast-tp18737649p18737649.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.
Received on Wed 30 Jul 2008 - 16:49:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Jul 2008 - 17:32:58 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive