Re: [R] Averaging within a range of values

2012-01-17 Thread doggysaywhat
Thank you all for your help. It's working now. I chose to use the sqldf method and fn$ in the gsubfn package. I used fn$ so that I could put variables into the sqldf statement. This helped me to increase or decrease the window size in the Gene dataframe if I wanted to include values in the

Re: [R] Averaging within a range of values

2012-01-14 Thread Gabor Grothendieck
On Fri, Jan 13, 2012 at 6:34 AM, doggysaywhat chwh...@ucsd.edu wrote: Hello all. I have two data frames. Group       Start          End G1                     200               700 G2                     500               1000 G3                     2000        3000 G4                    

Re: [R] Averaging within a range of values

2012-01-14 Thread cberry
doggysaywhat chwh...@ucsd.edu writes: My apologies for the context problem. I'll explain. df1 is a matrix of genes labeled g1 through g5 with start positions in the START column and end positions in the END column. df2 is a matrix of chromatin modification values at positions along the

[R] Averaging within a range of values

2012-01-13 Thread doggysaywhat
Hello all. I have two data frames. Group Start End G1 200 700 G2 500 1000 G3 20003000 G4 40006000 G5 70008000 and Pos

Re: [R] Averaging within a range of values

2012-01-13 Thread Jeff Newmiller
Regarding your last question, read ?cut --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go...

Re: [R] Averaging within a range of values

2012-01-13 Thread doggysaywhat
Hello Jeff, thank you for the reply. I tried the cut function and I had two questions. How do I have the cut function take the first position in the start column in df1 as the first cut point and the first position in column 2 as the second cut point. The break variable seems to want a single

Re: [R] Averaging within a range of values

2012-01-13 Thread Jeff Newmiller
Lack of context and examples is making this hard to follow, but my stabs at answers are 1) cut cannot guarantee that all numeric inputs will have unique factor results if you use two columns to define the ranges. That is, the ranges could overlap (multiple answers), or there could be gaps (no

Re: [R] Averaging within a range of values

2012-01-13 Thread doggysaywhat
My apologies for the context problem. I'll explain. df1 is a matrix of genes labeled g1 through g5 with start positions in the START column and end positions in the END column. df2 is a matrix of chromatin modification values at positions along the DNA. I want to average chromatin

Re: [R] Averaging within a range of values

2012-01-13 Thread doggysaywhat
Hello Rui, I didn't see your post before I posted. I'll try that out tomorrow. Many thanks. -- View this message in context: http://r.789695.n4.nabble.com/Averaging-within-a-range-of-values-tp4291958p4294137.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] Averaging within a range of values

2012-01-13 Thread Jeff Newmiller
I don't think my advice to use cut is in fact working, because the ranges are overlapping. Following is a reproducible example... as the posting guide indicates, you should provide self-contained examples like this in future questions posted to the list. # begin example tc - textConnection(

Re: [R] Averaging within a range of values

2012-01-13 Thread Rui Barradas
Hello, I believe this works res - NULL for(i in 1:nrow(df1)){ brk - df1[i, 2:3] ix - df2$Pos = brk$Start df2$Pos = brk$End res - rbind(res, apply(df2[ix, -1], 2, mean)) } res It's not very pretty but since the ranges can overlap, I'm not finding anything prettier