Re: [R] creating table with sequences of numbers based on the table

2014-03-14 Thread Gosia Gazda
: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

Re: [R] creating table with sequences of numbers based on the table

2014-03-13 Thread David Carlson
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

Re: [R] creating table with sequences of numbers based on the table

2014-03-13 Thread William Dunlap
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

Re: [R] creating table with sequences of numbers based on the table

2014-03-13 Thread Arunkumar Srinivasan
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

Re: [R] creating table with sequences of numbers based on the table

2014-03-13 Thread Dennis Murphy
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 <-

Re: [R] creating table with sequences of numbers based on the table

2014-03-13 Thread arun
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