Re: [R] Replicating Rows

2013-07-12 Thread arun
Hi, apple- read.table(text= Fam.name,Item,AMT.SALE.NET.PROMO,X.CY..QTY.SALE.TOT 9475,Imported Fruits,22110276001,0,436 9499,Imported Fruits,22110277001,0,236 9523,Imported Fruits,22110278001,0,71 ,sep=,,header=TRUE,stringsAsFactors=FALSE) str(apple) #'data.frame':    3 obs. of  4 variables: # $

Re: [R] Replicating Rows

2008-05-08 Thread Tony Plate
Another way is using straightforward indexing: x - cbind(trips=c(1,3,2), y=1:3, z=4:6) x trips y z [1,] 1 1 4 [2,] 3 2 5 [3,] 2 3 6 # generate row indices with the appropriate # number of repeats ii - rep(seq(len=nrow(x)), x[,1]) [1] 1 2 2 2 3 3 # use these indices to

[R] Replicating Rows

2008-05-07 Thread mwittmann
Hi, I have a data matrix in which there are 1000 rows by 30 columns. The first column of each row is a numeric indicating the number of trips taken to a particular location with location attributes in the following column entries for that row. I want to repeat each row based on the number

Re: [R] Replicating Rows

2008-05-07 Thread Jorge Ivan Velez
Hi Marion, Try this: set.seed(123) mydf=data.frame(trips=rpois(10,5), matrix(rnorm(10*5),ncol=5)) mydf sapply(mydf[,-1],rep,mydf[,1]) HTH, Jorge On Wed, May 7, 2008 at 11:41 PM, [EMAIL PROTECTED] wrote: Hi, I have a data matrix in which there are 1000 rows by 30 columns. The first