[R] Average value in a particular range of a matrix

David Winsemius dwinsemius at comcast.net
Fri Jun 13 03:02:26 CEST 2014


On Jun 12, 2014, at 5:11 AM, Pat-74100 wrote:

> 
> Hi
> 
> @Rolf Turner: So you're wrong, I can guaranty you this is not homework ... but just for a graph I'm trying do plot.
> 
> @Arun: Yes I've done a mistake, it is 1-100 , 101-200 etc .. or even 1-50,51-100 etc. The range is not important.
> 

In that case,  something along the lines of :

  sapply( seq(1, maxval, by=50), function (x) mean( some_object[x:(x+49)] ) )

Pretty basic. The advice to read more basic tutorials and play around with the common loop idioms on their help page examples might be worth your effort.

-- 
david.



> Thanks
> 
> 
>> Date: Thu, 12 Jun 2014 02:04:26 -0700
>> From: smartpink111 at yahoo.com
>> Subject: Re: [R] Average value in a particular range of a matrix
>> To: leonardsquall15 at hotmail.com
>> 
>> Hi Pat,
>> Is it 1-100, 101-200, 201-300,.. or just the way you described?
>> A.K.
>> 
>> 
>> 
>> 
>> On Wednesday, June 11, 2014 11:45 PM, Pat-74100 <leonardsquall15 at hotmail.com> wrote:
>> Hi
>> 
>> I have a matrix with values of size 1*500  i have to find the avg 
>> value of first 1 to 100 ,avg value of 100 - 200 and so on up to 400-500.
>> is there any function to find the average of 1 -100 and 100 - 200, 200 -
>> 300,300 - 400,400 - 500 ??
>> 
>> Thanks


David Winsemius
Alameda, CA, USA



More information about the R-help mailing list