Re: [R] apply with multiple conditions

2012-07-02 Thread pguilha
Thank you both very much! the factor issue was indeed solved by your modifications, and Jean that last bit of code does exactly what I need. Perfect! thanks again paul On 2 July 2012 21:34, Jean V Adams [via R] wrote: > Thanks for the intrusion! I have > options(stringsAsFactors=FALSE) >

Re: [R] apply with multiple conditions

2012-07-02 Thread Jean V Adams
Thanks for the intrusion! I have options(stringsAsFactors=FALSE) and Paul probably doesn't, so he saw factors where I saw characters. Paul, I saw your other note ... try this code L <- nrow(df) # assign a new bin every time chrom changes prev.chrom <- c(NA, df$chrom[-L]) bin1 <- cumsum

Re: [R] apply with multiple conditions

2012-07-02 Thread Rui Barradas
Hello, Sorry to intrude, but I think it's a factor issue. Try the changing the disjunction to, (in multiline edit) new.bin <- is.na(prev.chrom) | df$chrom != levels(df$chrom)[prev.chrom] | delta.start >= 115341 It should work, now. Hope this helps, Rui Barrada

Re: [R] apply with multiple conditions

2012-07-02 Thread pguilha
Jean, It's crazy, I'm still getting 1,2,3,4,5,6 in the bin column. Also (this is an unrelated problem i think), unless I've misunderstood it, I think your code will only create a new bin if the difference between chromStart at i and i-1 position is >=115341What I want is for a new bin to be

Re: [R] apply with multiple conditions

2012-07-02 Thread Jean V Adams
Paul, Try this (I changed some of the object names, but the meat of the code is the same): df <- data.frame( chrom = c("chr1", "chr1", "chr2", "chr2", "chr2", "chr2"), chromStart = c(10089, 10132, 10133, 10148, 210382, 216132), chromEnd = c(10309, 10536, 10362, 10418, 2

Re: [R] apply with multiple conditions

2012-07-02 Thread pguilha
Jean, that's exactly what it should be, but yes I copied and pasted from your email so I don't see how I could have introduced an error in there paul On 2 July 2012 15:57, Jean V Adams [via R] wrote: > Paul, > > Are you submitting the exact code that I included in my previous e-mail? > When I

Re: [R] apply with multiple conditions

2012-07-02 Thread Jean V Adams
Paul, Are you submitting the exact code that I included in my previous e-mail? When I submit that code, I get this ... chrom chromStart chromEnd name cumsum bin 1 chr1 1008910309 ZBTB33 10089 1 2 chr1 1013210536 TAF7_(SQ-8) 20221 1 3 chr2 10133

Re: [R] apply with multiple conditions

2012-07-02 Thread Paul Guilhamon
Thanks for your reply Jean, I think your interpretation is correct but when I run your code I end up with the below dataframe and obviously the bins created there don't correspond to a chromStart change of 115341: chrom chromStart chromEnd name cumsum bin 1 chr1 1008910309

Re: [R] apply with multiple conditions

2012-07-02 Thread Jean V Adams
Paul, My interpretation is that you are trying to assign a new bin number to a row every time the variable chrom changes and every time the variable chromStart changes by 115341 or more. Is that right? If so, you don't need a loop at all. Check out the code below. I made a couple changes to

[R] apply with multiple conditions

2012-07-02 Thread pguilha
Hello all, I have written a for loop to act on a dataframe with close to 3million rows and 6 columns and I would like to pass it to apply() to speed the process up (I let the loop run for 2 days before stopping it and it had only gone through 200,000 rows) but I am really struggling to find a way