r-help-boun...@r-project.org wrote on 01/25/2010 02:39:32 PM: > x <- read.table(textConnection("col1 col2 > 3 1 > 2 2 > 4 7 > 8 6 > 5 10"), header=TRUE) > > I want to rewrite it as below: > > var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 > 1 0 1 0 0 0 0 0 0 0 > 0 2 0 0 0 0 0 0 0 0 > 0 0 0 1 0 0 1 0 0 0 > 0 0 0 0 0 1 0 1 0 0 > 0 0 0 0 1 0 0 0 0 1 > > Can anybody please help how to get this done? Your help would be greatly > appreciated.
Thanks, I've not seen textConnection() before. The table() function will get you close: table(c(rownames(x),rownames(x)), c(x$col1,x$col2)) cur -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.c...@epa.gov 541/754-4638 [[alternative HTML version deleted]] ______________________________________________ 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.