[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applying function to vector by index

From: Mike Miller
Subject: Re: Applying function to vector by index
Date: Mon, 9 Dec 2002 10:51:45 -0600 (CST)

On Mon, 9 Dec 2002, Iago Mosqueira wrote:

> I have a long vector classified in ten bins of different length
> according to another vector.

How does the second vector specify the bins in the first vector?  Can you
give an example?

> I want to estimate the variance, or any other function, of the values
> from the first vector for each of the categories described by the
> second, without using a loop. Is there any obvious way of doing this I
> am overlooking? In R one could do
>     sapply(split(d,idx),var)
> where d is my data vector and idx the index vector.

It depends on what is in 'idx'.  It could be something like this...


...and it would be exactly that if the elements of idx specified the
elements of d for which the variance was to be computed.


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]