Reputation: 9778
R is used for statistical computing. I don't know statistics never worked with R. I was given this formula in "R" to solve a problem, but need help to translate it into either MySQL or PHP. Below is a direct quote:
In R we can compute
x <- matrix(c(-954234, 3589, 43243455, 2521, 149940475, 3939, 243853640, 3936, 262995399, 3025, 751195421, 5333, 10677437299, 7477), ncol=2, byrow=TRUE); y <- apply(x, 2, sum); y[1] / y[2],
producing $406,697 for the average.
Some background information on this. This is data from the IRS 2008 for Income Tax data by zip code. The above data is from a single zip code (10021). The table (please see below). The task is to create an Average Adjust Gross Income (AGI), and the above R example is the solution. Thanks!
1 = 'Under $10,000'
2 = '$10,000 under $25,000'
3 = '$25,000 under $50,000'
4 = '$50,000 under $75,000'
5 = '$75,000 under $100,000'
6 = '$100,000 under $200,000'
7 = '$200,000 or more '
"Number of Returns" is the Number of tax returns for that agi_class.
mysql> select A00100,zipcode,agi_class,N1 as 'Number of Returns' from taxbyzip2008 where zipcode="10021";
+-------------+---------+-----------+-------------------+
| A00100 | zipcode | agi_class | Number of Returns |
+-------------+---------+-----------+-------------------+
| -954234 | 10021 | 1 | 3589 |
| 43243455 | 10021 | 2 | 2521 |
| 149940475 | 10021 | 3 | 3939 |
| 243853640 | 10021 | 4 | 3936 |
| 262995399 | 10021 | 5 | 3025 |
| 751195421 | 10021 | 6 | 5333 |
| 10677437299 | 10021 | 7 | 7477 |
+-------------+---------+-----------+-------------------+
Upvotes: 0
Views: 205
Reputation: 14500
try this :
select sum(A00100)/sum(N1) as 'average' from taxbyzip2008 where zipcode="10021";
OR quick try:
mysql> select (-954234 + 43243455 +149940475 + 243853640 + 262995399 + 751195421+10677437299)/(3589+2521 +3939 +3936 +3025 + 5333 + 7477) ;
your formula is sum of A00100 divide by sum of N1 field :)
Upvotes: 1