Hi David, According to your question below, the reason that d2 fail is that sub[41,] supposes to pick out the 41th row in the sub matrix, rather than the row with case=41. When you subset the original d matrix, the value of case doesn't not correspond to the number of row any more. However, it should still work on the d matrix and that's why d3 still work. Hope it helps. Yannan > Hello again allstat, > Your help is needed again. Thanks for your help with the initial question. > See below. > # Dataset > case <- 1:50 > x<-case*100 > y<-case/100 > d<-data.frame(case,x,y) > > sub<-d[x>=2500,] > sub > # sample 10 cases with replacement from sub > s<-sample(sub$case,size=10,replace=TRUE) > > # why does d2 fail ?? Is d3 the only solution (which oddly needs to refer > back to d) ?? > d2<-sub[s,] > d2 > d3<-d[s,] > d3 > > > > > > ======================================== > Message Received: Feb 14 2008, 04:33 PM > From: "David" > To: [log in to unmask] > Cc: > Subject: R question > > Hi allstat, > I need help with the following R dataset manipulation problem. No doubt > its easy!?? Thanks if you can help. > # pretent dataset > case <- 1:50 > x<-case*100 > y<-case/100 > d<-data.frame(case,x,y) > # sample 10 cases with replacement from d > s<-sample(case,size=10,replace=TRUE) > # now want to create a dafaset of length 10 rows > # of the same form "case,x,y" but corresponding to the sampled x's > # Eg. for s=(12 12 14 12 11 37 47 35 11 22 14) > # want ... > # 12 1200 .12 > # 12 1200 .12 > # 14 1400 .14 > # 12 1200 .12 > # etc.... > thanks > David >