Re: [R] how to save this result in a vector

2010-11-01 Thread Erich Neuwirth
My guess is that what you want probably is best done by using ecdf. You might want to look it up in the docs. 1-ecdf(test)(x) Will give you the percentage of values in test larger than x. On 11/1/2010 2:24 AM, Changbin Du wrote: Thanks Joshua! Yes, i is not going up sequentially by 1, as i

Re: [R] how to save this result in a vector

2010-11-01 Thread Changbin Du
Thanks, Erich! On Mon, Nov 1, 2010 at 4:55 AM, Erich Neuwirth erich.neuwi...@univie.ac.atwrote: My guess is that what you want probably is best done by using ecdf. You might want to look it up in the docs. 1-ecdf(test)(x) Will give you the percentage of values in test larger than x. On

[R] how to save this result in a vector

2010-10-31 Thread Changbin Du
HI, Dear R community, I have the following codes to calculate the commulative coverage. I want to save the output in a vector, How to do this? test-seq(10, 342, by=2) #cover is a vector cover_per-function (cover) { for (i in min(cover):max(cover)) {print(100*sum(ifelse(cover = i, 1,

Re: [R] how to save this result in a vector

2010-10-31 Thread Joshua Wiley
Hi Changbin, The yek is that you need to save the results of your for loop rather than just printing it. It also may be possible to vectorize your for loop which might simplify things and speed them up, but I did not look at that. Here is one way to save the results, see inline comments for

Re: [R] how to save this result in a vector

2010-10-31 Thread David Winsemius
On Oct 31, 2010, at 8:35 PM, Changbin Du wrote: HI, Dear R community, I have the following codes to calculate the commulative coverage. Not sure exactly what you mean by this. My guess is implemented below. I want to save the output in a vector, How to do this? test-seq(10, 342, by=2)

Re: [R] how to save this result in a vector

2010-10-31 Thread Joshua Wiley
On Sun, Oct 31, 2010 at 5:44 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: snip #cover is a vector cover_per - function(cover) {  ## create a vector to store the results of your for loop  output - vector(numeric, length(min(cover):max(cover)))  for (i in min(cover):max(cover)) {    ##

Re: [R] how to save this result in a vector

2010-10-31 Thread Changbin Du
HI, David, Juan, and Joshua, Thanks so much for your help! The following codes works. Appreciated! test-seq(10, 342, by=2) #data is a vector cover_per-function (data) { output-vector(numeric,length(min(data):max(data))) for (i in min(data):max(data)) {

Re: [R] how to save this result in a vector

2010-10-31 Thread Changbin Du
Thanks Joshua! Yes, i is not going up sequentially by 1, as i here is the raw number of reads for each DNA base. Thanks so much for the great help! On Sun, Oct 31, 2010 at 6:03 PM, Joshua Wiley jwiley.ps...@gmail.comwrote: On Sun, Oct 31, 2010 at 5:44 PM, Joshua Wiley jwiley.ps...@gmail.com