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
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
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
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 .
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
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
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
> 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
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
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
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
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
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
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
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
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
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
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
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"
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
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
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
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
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<-
> 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
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
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
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
28 matches
Mail list logo