Re: [R] Simple but elusive - expand back from counts

2011-03-29 Thread jjap
Many thanks to all, the first 3 solutions worked nicely but I did not get around to tweaking properly the others. It's really nice to get thing going in a "one liner" or about... Again greatly appreciated. Cheers! -- View this message in context: http://r.789695.n4.nabble.com/Simple-but-elusive-e

Re: [R] Simple but elusive - expand back from counts

2011-03-29 Thread Henrique Dallazuanna
Try this: transform(tmp[rep(seq(nrow(tmp)), as.numeric(tmp$V4)),], V4 = 1) On Tue, Mar 29, 2011 at 3:15 PM, jjap wrote: > Dear R-users, > > This should be simple but still eludes me: > > Given the following > tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12, > "abc", 2), 3,

Re: [R] Simple but elusive - expand back from counts

2011-03-29 Thread Peter Alspach
p@r-project.org > Subject: [R] Simple but elusive - expand back from counts > > Dear R-users, > > This should be simple but still eludes me: > > Given the following > tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12, >

Re: [R] Simple but elusive - expand back from counts

2011-03-29 Thread Petr Savicky
On Tue, Mar 29, 2011 at 11:15:33AM -0700, jjap wrote: > Dear R-users, > > This should be simple but still eludes me: > > Given the following > tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12, > "abc", 2), 3, 4, byrow=T)) > > I want to expand the data to the following form

Re: [R] Simple but elusive - expand back from counts

2011-03-29 Thread Joshua Wiley
Hi, You can use rep() to repeat the appropriate rows as in V4. For example: tmp[rep(rownames(tmp), tmp$V4), ] V1 V2 V3 V4 1 44 10 abc 1 2 44 10 def 1 3 44 12 abc 2 3.1 44 12 abc 2 if you wanted, you could then reset the row names to NULL to get 1, 2, 3, 4 rather than 3, 3.1 row

[R] Simple but elusive - expand back from counts

2011-03-29 Thread jjap
Dear R-users, This should be simple but still eludes me: Given the following tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12, "abc", 2), 3, 4, byrow=T)) I want to expand the data to the following form: V1 V2 V3 V4 1 44 10 abc 1 2 44 10 def 1 3 44 12 abc 1 4 44 12 a