Dnia 2011-06-15, o godz. 12:05:01 Jim Lemon <j...@bitwrit.com.au> napisaĆ(a):
> On 06/15/2011 06:46 PM, filip.biele...@rega.kuleuven.be wrote: > > Dear, > > > > I have a data frame melted from a list of matrices (melt from > > reshape package), then I impute some missing values and then want > > to tabulate the data again to the array (or list, doesn't matter) > > of matrices form. However when using xtabs function it orders my > > rows alphabetically and apparently doesn't take "reorder = FALSE" > > option or anything like it. Is there anything I can do to stop it > > from doing so? > > > > Relevant parts of code: > > > > matrices.m<- melt(combined_list) > > > > matrices.m_i[is.na(matrices.m_i$value),]$value<- predictions > > > > matrices<- xtabs(value ~ location + variable + week, data = > > matrices.m_i) > > > Hi filip, > Have you tried specifically classing your variables as factors and > using the "ordered" argument? > > Jim > Dear, That's exacly what the problem was - the factor levels are by default in alphabetical order, so I had to fix that by: levels(matrices.m_i$location) <- unique(as.character(matrices.m_i$location)) levels(matrices.m_i$variable) <- unique(as.character(matrices.m_i$variable)) Then xtabs works as advertised. Cheers, filip -- while(!succeed) { try(); } ______________________________________________ R-help@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.