Re: [R] rle with data.table - is it possible?

2015-01-03 Thread Kate Ignatius
Ahh ... you may have missed this: Larger example below. So for the below example it will be: Dad Mum Child Group sumdad summum sumchild childseg 1: AA RRRA A 2 200 2: AA RRRR A 2 211 3: AA AAAA B 4

Re: [R] rle with data.table - is it possible?

2015-01-02 Thread Beejai
What are you having trouble with exactly? Do you need a bigger example. The code works perfectly well with your code so I'm sure how you are finding trouble with it (minus the fact that I had put in a few errors in myself at the beginning with I apologize). On Fri, Jan 2, 2015 at 9:05 PM, Jeff N

Re: [R] rle with data.table - is it possible?

2015-01-02 Thread Jeff Newmiller
Here is what I get when I try to use your algorithm: myf <- function( s ) { seg <- rep( 0, length( s ) ) rs <- rle( s ) span <- rs$lengths[ rs$values ] seg[ s ] <- rep( seq_along( span ), times = span ) seg } DT <- data.table( x ) DT[ , dadseg := myf( Dad %in% c( "AA", "RR" ) ), by=Gro

Re: [R] rle with data.table - is it possible?

2015-01-02 Thread Jeff Newmiller
The problem is that I cannot see how your use of rle and/or seq_along could possibly lead to the sample result you are giving us. That is why I asked for a new example. --- Jeff NewmillerThe .

Re: [R] rle with data.table - is it possible?

2015-01-02 Thread Beejai
Obviously this is why I need help... This is a larger data frame. I'm only posting something small here to make it simple. There are many Groups which are larger, and I want to assign a sequence value to consecutive rows where sumchild in not equal to 0. As the data frame I'm working with is mu

Re: [R] rle with data.table - is it possible?

2015-01-02 Thread David Winsemius
On Jan 2, 2015, at 12:07 AM, Kate Ignatius wrote: > Ah, crap. Yep you're right. This is not going too well. Okay - let > me try that again: > > x$childseg<-0 > x<-x$sumchild !=0 That previous line would appear to overwrite the entire dataframe with the value of one vector > span<-rle(x)$len

Re: [R] rle with data.table - is it possible?

2015-01-02 Thread Kate Ignatius
Ah, crap. Yep you're right. This is not going too well. Okay - let me try that again: x$childseg<-0 x<-x$sumchild !=0 span<-rle(x)$lengths[rle(x)$values==TRUE] x$childseg[x]<-rep(seq_along(span), times = span) Does this one have any errors? On Fri, Jan 2, 2015 at 2:32 AM, David Winsemius wro

Re: [R] rle with data.table - is it possible?

2015-01-01 Thread David Winsemius
> On Jan 1, 2015, at 5:07 PM, Kate Ignatius wrote: > > Apologies - mix up of syntax all over the place, a habit of mine. The > last line was in there because of code beforehand so it really doesn't > need to be there. Here is the proper code I hope: > > childseg<-0 > x<-sumchild ==0 > span<-r

Re: [R] rle with data.table - is it possible?

2015-01-01 Thread Kate Ignatius
Apologies - mix up of syntax all over the place, a habit of mine. The last line was in there because of code beforehand so it really doesn't need to be there. Here is the proper code I hope: childseg<-0 x<-sumchild ==0 span<-rle(x)$lengths[rle(x)$values==TRUE] childseg[x]<-rep(seq_along(span), t

Re: [R] rle with data.table - is it possible?

2015-01-01 Thread Jeff Newmiller
Thank you for attempting to encode what you want using R syntax, but you are not really succeeding yet (too many errors). Perhaps another hand generated result would help? A new input data frame might or might not be needed to illustrate desired results. Your second and third lines are syntact

Re: [R] rle with data.table - is it possible?

2015-01-01 Thread Kate Ignatius
Is it possible to add the following code or similar in data.table: childseg<-0 x:=sumchild <-0 span<-rle(x)$lengths[rle(x)$values==TRUE childseg[x]<-rep(seq_along(span), times = span) childseg[childseg == 0]<-'' I was hoping to do this code by Group for mum, dad and child. The problem I'm having

Re: [R] rle with data.table - is it possible?

2014-12-31 Thread Kate Ignatius
correct code: childseg<-0 x:=sumchild <-0 span<-rle(x)$lengths[rle(x)$values==TRUE childseg[x]<-rep(seq_along(span), times = span) childseg[childseg == 0]<-'' On Thu, Jan 1, 2015 at 1:56 AM, Kate Ignatius wrote: > Is it possible to add the following code or similar in data.table: > > childseg<-0

Re: [R] rle with data.table - is it possible?

2014-12-31 Thread Kate Ignatius
Is it possible to add the following code or similar in data.table: childseg<-0 x:=sumchild <-0 span<-rle(x)$lengths[rle(x)$values==TRUE childseg[x]<-rep(seq_along(span), times = spanLOH) childseg[childseg == 0]<-'' I was hoping to do this code by SNPEFF_GENE_NAME for mum, dad and child. The prob

Re: [R] rle with data.table - is it possible?

2014-12-31 Thread Jeff Newmiller
I do not understand the value of using the rle function in your description, but the code below appears to produce the table you want. Note that better support for the data.table package might be found at stackexchange as the documentation specifies. x <- read.table( text= "Dad Mum Child Grou

[R] rle with data.table - is it possible?

2014-12-30 Thread Kate Ignatius
I'm trying to use both these packages and wondering whether they are possible... To make this simple, my ultimate goal is determine long stretches of 1s, but I want to do this within groups (hence using the data.table as I use the "set key" option. However, I'm I'm not having much luck making thi

Re: [R] rle for non concecutive

2011-10-31 Thread Paul Hiemstra
On 10/31/2011 09:34 AM, Joshua Wiley wrote: > On Mon, Oct 31, 2011 at 2:29 AM, Alaios wrote: >> Dear all, >> I would like to task you if you know a rle version that can work also in a >> non consecutive way too. The whole idea of rle is to have consecutive runs. Please specify more clearly what

Re: [R] rle for non concecutive

2011-10-31 Thread Joshua Wiley
On Mon, Oct 31, 2011 at 2:29 AM, Alaios wrote: > Dear all, > I would like to task you if you know a rle version that can work also in a > non consecutive way too. You mean just a counter for an objects occurence? like: A B A A B B C would give 1 1 2 3 2 3 1? I am not clear what non consecutive

[R] rle for non concecutive

2011-10-31 Thread Alaios
Dear all, I would like to task you if you know a rle version that can work also in a non consecutive way too. B.R Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEAS

[R] Rle function to expand for many samples

2011-09-28 Thread sujitha
Dear R experts, code: >m<-read.table("test.txt",sep='\t',header=TRUE,colClasses=c('character','integer','integer','rep('numeric',150)) > s<-data.frame(c(rle(m$Sample1)[[2]],rle(m$Sample2)[[2]],rle(m$Sample3)[[2]]),c(rle(m$Sample1)[[1]],rle(m$Sample2)[[1]],rle(m$Sample3)[[1]])) > names(s)=c("Values"

[R] rle with NA values?

2011-06-24 Thread Justin Haynes
Happy Friday! Using this function: fixSeq <- function(df) { shift1 <- function(x) c(1, x[-length(x)]) df$state_shift<-df$state df.rle<-rle(df$state_shift) repeat { shifted.sf<-shift1(df.rle$values) change <- df.rle$values >= 4 & shifted.sf >= 4 & shifted.sf != df.rle$values if

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<-

Re: [R] rle

2009-07-07 Thread Richard . Cotton
> I have an other problem, I have this vector signData with an alternation of > 1 and -1 that corrispond to the duration of two different percepts. I > extracted the durations like this: > > signData<- scan("dataTR10.txt") > dur<-rle(signData)$length I think that last line should be dur<-rle(si

Re: [R] rle

2009-07-07 Thread Henrique Dallazuanna
Or: with(rle(signData), lengths[values == 1]) On Tue, Jul 7, 2009 at 8:26 AM, Henrique Dallazuanna wrote: > Try this: > > rle(signData)$lengths[rle(signData)$values == 1] > > > On Tue, Jul 7, 2009 at 8:11 AM, aledanda wrote: > >> >> Hallo, >> >> I have an other problem, I have this vector sign

Re: [R] rle

2009-07-07 Thread Henrique Dallazuanna
Try this: rle(signData)$lengths[rle(signData)$values == 1] On Tue, Jul 7, 2009 at 8:11 AM, aledanda wrote: > > Hallo, > > I have an other problem, I have this vector signData with an alternation of > 1 and -1 that corrispond to the duration of two different percepts. I > extracted the durations

[R] rle

2009-07-07 Thread aledanda
Hallo, I have an other problem, I have this vector signData with an alternation of 1 and -1 that corrispond to the duration of two different percepts. I extracted the durations like this: signData<- scan("dataTR10.txt") dur<-rle(signData)$length Now I would like to extract only the positive dur