[R] Expanding data ...

From: John Poulsen <jpoulsen_at_zoo.ufl.edu>
Date: Sun, 16 Nov 2008 07:31:04 -0500


I have a dataset that has counts, but I need to expand the dataset so that each of the counts has its own line in the dataset (row) and is given and id. It looks something like:

Site	Type	Cnt
1	"A"	3
1	"B"	0
2	"C"	2

I want the dataset to look like:

Site	Type	ID	
1	"A"	1
1	"A"	2	
1	"A"	3
1	"B"	0
2	"C"	1
2	"C"	2

I can do this using loops, but I was wondering if anyone knows a more efficient way of expanding the data on counts and giving id numbers.

Thanks for your help,

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 Sun 16 Nov 2008 - 12:43:55 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 Sun 16 Nov 2008 - 14:00:25 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