[R] how to work with long vectors

jim holtman jholtman at gmail.com
Thu Nov 4 17:18:19 CET 2010

```Is this what you want:

> x
1   Contig79:1     4
2   Contig79:2     8
3   Contig79:3    13
4   Contig79:4    14
5   Contig79:5    17
6   Contig79:6    20
7   Contig79:7    25
8   Contig79:8    27
9   Contig79:9    32
10 Contig79:10    33
11 Contig79:11    34
> x
1   Contig79:1     4  11.76471
2   Contig79:2     8  23.52941
3   Contig79:3    13  38.23529
4   Contig79:4    14  41.17647
5   Contig79:5    17  50.00000
6   Contig79:6    20  58.82353
7   Contig79:7    25  73.52941
8   Contig79:8    27  79.41176
9   Contig79:9    32  94.11765
10 Contig79:10    33  97.05882
11 Contig79:11    34 100.00000

On Thu, Nov 4, 2010 at 11:46 AM, Changbin Du <changbind at gmail.com> wrote:
> HI, Dear R community,
>
> I have one data set like this,  What I want to do is to calculate the
> cumulative coverage. The following codes works for small data set (#rows =
> 100), but when feed the whole data set,  it still running after 24 hours.
> Can someone give some suggestions for long vector?
>
> Contig79:1    4
> Contig79:2    8
> Contig79:3    13
> Contig79:4    14
> Contig79:5    17
> Contig79:6    20
> Contig79:7    25
> Contig79:8    27
> Contig79:9    32
> Contig79:10    33
> Contig79:11    34
>
> dim(matt)
> [1] 3384766       2
>
> matt_plot<-function(matt, outputfile) {
>
>
>
> #calculate the cumulative coverage.
> + cover_per<-function (data) {
> + output<-numeric(0)
> + for (i in data) {
> +           x<-(100*sum(ifelse(data >= i, 1, 0))/length(data))
> +           output<-c(output, x)
> +                 }
> + return(output)
> + }
>
>
>  result<-cover_per(cover)
>
>
> Thanks so much!
>
>
> --
> Sincerely,
> Changbin
> --
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

```