Hi, I am investigating a problem for which I found no solution. I have a matrix with two columns. I have plotted it as an x-y plot (plot(matrix[,1],matrix[,2]) But this is not apropriate for my purposes. I need to group the data in matrix[,1] into groups (as an histogram would do). Then I have to calculate the average of matrix[,2] for each group. Before starting with loops and loops I would like to know if is there some way to do this easily with R. Thanks in advance! Federico
Hi Federico, Have you checked google R graph library? bests milton On Thu, Oct 29, 2009 at 3:12 PM, Federico Abascal <fedeabascal@yahoo.es>wrote:> Hi, > > I am investigating a problem for which I found no solution. > I have a matrix with two columns. I have plotted it as an x-y plot > (plot(matrix[,1],matrix[,2]) > But this is not apropriate for my purposes. I need to group the data in > matrix[,1] into groups (as an histogram would do). Then I have to calculate > the average of matrix[,2] for each group. > > Before starting with loops and loops I would like to know if is there some > way to do this easily with R. > > Thanks in advance! > Federico > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On Oct 29, 2009, at 3:12 PM, Federico Abascal wrote:> Hi, > > I am investigating a problem for which I found no solution. > I have a matrix with two columns. I have plotted it as an x-y plot > (plot(matrix[,1],matrix[,2]) > But this is not apropriate for my purposes. I need to group the data > in matrix[,1] into groups (as an histogram would do). Then I have to > calculate the average of matrix[,2] for each group.?boxplot # you get the median instead of the mean. Perhaps: boxplot(matrix[,1],matrix[,2])> Before starting with loops and loops I would like to know if is > there some way to do this easily with R. > > Thanks in advance! > Federico > > ______________________________________________ > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
On 10/30/2009 06:12 AM, Federico Abascal wrote:> Hi, > > I am investigating a problem for which I found no solution. > I have a matrix with two columns. I have plotted it as an x-y plot > (plot(matrix[,1],matrix[,2]) > But this is not apropriate for my purposes. I need to group the data > in matrix[,1] into groups (as an histogram would do). Then I have to > calculate the average of matrix[,2] for each group. > > Before starting with loops and loops I would like to know if is there > some way to do this easily with R.Hi Federico, If I understand your problem, I think you want first to use "cut": groups<-cut(matrix[1,],breaks=???) where ??? is the vector of breakpoints that you want. Then you can use whatever averaging function (AVEFUN) you want with something like "by": by(matrix[,2],groups,AVEFUN) Jim