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 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.com>wrote: > >> 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)) { >>> ## rather than print()ing the output, assign it to an object >>> output[i] <- 100*sum(ifelse(cover >= i, 1, 0))/length(cover) >>> } >>> ## have the return value from the function be >>> ## the object 'output' >>> return(output) >>> } >> >> I did not catch that i was not necessarily starting at 1 going >> sequentially up, so that would have to be done manually (or use cumsum >> per David rather than the function you wrote). >> >> cover_per2 <- function(cover) { >> output <- vector("numeric", length(min(cover):max(cover))) >> j <- 1 >> for (i in min(cover):max(cover)) { >> output[j] <- 100*sum(ifelse(cover >= i, 1, 0))/length(cover) >> j <- j + 1 >> } >> return(output) >> } >> >> Josh >> > > > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.