# Average value in a particular range of a matrix

6 messages
Open this post in threaded view
|

## Average value in a particular range of a matrix

 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               [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Average value in a particular range of a matrix

 On 12/06/14 00:17, Pat-74100 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 ?? This looks very much like homework.  The r-help list has a "no homework" policy.  Do your own homework.  That way you might actually learn something! cheers, Rolf Turner ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Average value in a particular range of a matrix

 In reply to this post by Pat-74100 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. Thanks > Date: Thu, 12 Jun 2014 02:04:26 -0700 > From: [hidden email] > Subject: Re: [R] Average value in a particular range of a matrix > To: [hidden email] > > 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 <[hidden email]> 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 >                           >     [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Average value in a particular range of a matrix

 Hi, Try: set.seed(45) mat1 <- matrix(rnorm(500), ncol=1)  n <- dim(mat1)[1] indx <- as.numeric(gl(n,100,n))  tapply(mat1[,1], indx, FUN= mean, na.rm=TRUE) #          1           2           3           4           5 # 0.08118335 -0.05222418 -0.20042223 -0.03530833 -0.06093053 If you have more than one column: set.seed(49)  dat1 <- as.data.frame(matrix(rnorm(1000), ncol=2)) library(plyr) ddply(dat1,.(indx), numcolwise(mean, na.rm=TRUE)) A.K. On Thursday, June 12, 2014 8:11 AM, Pat-74100 <[hidden email]> 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. Thanks > Date: Thu, 12 Jun 2014 02:04:26 -0700 > From: [hidden email] > Subject: Re: [R] Average value in a particular range of a matrix > To: [hidden email] > > 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 <[hidden email]> 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 >                           >     [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] 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. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.