On 05/24/2010 10:21 PM, Mohan L wrote:
... in this case the state column becomes the row index. I want the state name as the first column. There may be a way to do it.
Hi Mohan, You can do it with this awful kludge, but there must be a better way: dummy<-data.frame( State=sample(c("NSW","NT","QLD","SA","TAS","WA"),100,TRUE), Month=sample(c("Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"),100,TRUE)) dummytab<-table(dummy$State,dummy$Month) dfdummytab<-data.frame(State=rownames(dummytab), Jan=dummytab[,5],Feb=dummytab[,4],Mar=dummytab[,8], Apr=dummytab[,1],May=dummytab[,9],Jun=dummytab[,7], Jul=dummytab[,6],Aug=dummytab[,2],Sep=dummytab[,12], Oct=dummytab[,11],Nov=dummytab[,10],Dec=dummytab[,3]) rownames(dfdummytab)<-NULL Jim ______________________________________________ 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.