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
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,
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,
>
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
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
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
6 matches
Mail list logo