Re: [R] sequential sum of a vector...

From: denise xifaras <denisexifaras_at_yahoo.com>
Date: Wed, 23 Jul 2008 09:28:30 -0700 (PDT)

Dear Patrizio and all,
Do you know a similar approach to this, so that *any* function is sequentially applied on a matrix? Particularly, instead of wanting to sum columns every 8 rows, how could we apply a linear regression to the columns of a matrix every 8 rows? ie, if we have a matrix say of 100 rows and 3 columns- say columns are price, production cost, desired profit.  How can we apply lm(price~production cost +desired profit) where the data is taken every 10 lines from the matrix, ie we end up with 10 different regressions?
Any help is welcome,
Thank you very much
Denise

• On Wed, 7/23/08, Patrizio Frederic <frederic.patrizio_at_gmail.com> wrote:

From: Patrizio Frederic <frederic.patrizio_at_gmail.com> Subject: Re: [R] sequential sum of a vector... To: "Shubha Vishwanath Karanth" <shubhak_at_ambaresearch.com> Cc: r-help_at_stat.math.ethz.ch
Date: Wednesday, July 23, 2008, 8:30 AM

try this

colSums(matrix(x,8))

regards,

PF

```+-------------------------------------------------
| Patrizio Frederic
| Research associate in Statistics,
| Department of Economics,
| University of Modena and Reggio Emilia,
| Via Berengario 51,
| 41100 Modena, Italy
|
| tel:  +39 059 205 6727
```

| fax: +39 059 205 6947
| mail: patrizio.frederic_at_unimore.it
```+-------------------------------------------------

```

2008/7/23 Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com>:
> Hi R,
>
>
>
> Let,
>
>
>
> x=1:80
>
>
>
> I want to sum up first 8 elements of x, then again next 8 elements of x,
> then again another 8 elements..... So, my new vector should look like:
>
> c(36,100,164,228,292,356,420,484,548,612)
>
>
>
> I used:
>
>
>
> aggregate(x,list(rep(1:10,each=8)),sum)[-1]
>
> or
>
> rowsum(x,group=rep(1:10,each=8))
>
>
>
>
>
> But without grouping, can I achieve the required? Any other ways of
> doing this?
>
>
>
> Thanks, Shubha
>
>
>
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

R-help_at_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.
```
[[alternative HTML version deleted]]

______________________________________________
```
R-help_at_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. Received on Wed 23 Jul 2008 - 17:29:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Jul 2008 - 17:32:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.