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 > -- Sincerely, Changbin -- Changbin Du DOE Joint Genome Institute Bldg 400 Rm 457 2800 Mitchell Dr Walnut Creet, CA 94598 Phone: 925-927-2856 [[alternative HTML version deleted]] ______________________________________________ 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.