:Re: [R] creating table with sequences of numbers based on the
table
I think this'll be way simpler and also faster:
ans <- data.frame(pop = rep.int(tab$pop, tab$Freq), ind=sequence(tab$Freq))
Arun
From:Â Dennis Murphy djmu...@gmail.com
Reply:Â Dennis Murphy djmu...@gmail.com
Date
014 3:55 PM
To: arun
Cc: R help
Subject: Re: [R] creating table with sequences of numbers based
on the table
Less coding with plyr:
tab <- read.table(text="pop Freq
1 1 30
2 2 25
3 3 30
4 4 30
5 5 30
6 6 30
7 7 30",sep="&qu
t.org] On
> Behalf
> Of Dennis Murphy
> Sent: Thursday, March 13, 2014 1:55 PM
> To: arun
> Cc: R help
> Subject: Re: [R] creating table with sequences of numbers based on the table
>
> Less coding with plyr:
>
> tab <- read.table(text="pop Freq
> 1
p r-help@r-project.org
Subject:Â Re: [R] creating table with sequences of numbers based on the table
Less coding with plyr:
tab <- read.table(text="pop Freq
1 1 30
2 2 25
3 3 30
4 4 30
5 5 30
6 6 30
7 7 30",sep="",header=TRUE)
# Function to do the work
Less coding with plyr:
tab <- read.table(text="pop Freq
1 1 30
2 2 25
3 3 30
4 4 30
5 5 30
6 6 30
7 7 30",sep="",header=TRUE)
# Function to do the work on each row
f <- function(pop, Freq) data.frame(ind = seq_len(Freq))
library(plyr)
u <-
Hi,
Try:
Either
tab <- read.table(text="pop Freq
1 1 30
2 2 25
3 3 30
4 4 30
5 5 30
6 6 30
7 7 30",sep="",header=TRUE)
indx <- rep(1:nrow(tab),tab$Freq)
tab1 <- transform(tab[indx,],ind=ave(seq_along(indx),indx,FUN=seq_along))[,-2]
#or
tab2
6 matches
Mail list logo