Re: [R] rle on large data . . . without a for loop!

2011-06-18 Thread Dennis Murphy
Hi Justin: I'm not dead certain this is what you were after, but try this: dat<-data.frame(id = rep(1:5, each = 200), state=sample(1:3, 1000, replace=TRUE, prob=c(0.7,0.05,0.25)), V1=runif(1000, 1, 10), V2=rnorm(1000)) ## input a data

Re: [R] rle on large data . . . without a for loop!

2011-06-17 Thread Justin
Justin gmail.com> writes: > > I think need to do something like this: > > > > dat<-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000, > > replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000)) > > brown bag... ... its friday and im sleepy!... dat<-data.frame(id=rep(1:5,each

Re: [R] rle on large data . . . without a for loop!

2011-06-17 Thread Justin
Justin Haynes gmail.com> writes: > > I think need to do something like this: > > dat<-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000, > replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000)) brown bag... dat<-data.frame(id=rep(1:5,each=200),state=sample(1:3, 1000, replac

[R] rle on large data . . . without a for loop!

2011-06-17 Thread Justin Haynes
I think need to do something like this: dat<-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000, replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000)) rle.dat<-rle(dat$state) temp<-1 out<-data.frame(id=1:length(rle.dat$length)) for(i in 1:length(rle.dat$length)){ temp2<-