R用于统计计算。我不知道统计数据从未与R一起工作。我在“R”中给出了这个公式来解决问题,但需要帮助将其转换为MySQL或PHP。以下是直接引用:
在R中我们可以计算
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],
平均产生406,697美元。
有关此问题的一些背景资料。这是来自IRS 2008的所得税数据的邮政编码数据。以上数据来自单个邮政编码(10021)。表(请见下文)。任务是创建平均调整总收入(AGI),上面的R示例是解决方案。谢谢!
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 '
“退货数量”是该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 |
+-------------+---------+-----------+-------------------+
答案 0 :(得分:1)
试试这个:
select sum(A00100)/sum(N1) as 'average' from taxbyzip2008 where zipcode="10021";
或快速尝试:
mysql> select (-954234 + 43243455 +149940475 + 243853640 + 262995399 + 751195421+10677437299)/(3589+2521 +3939 +3936 +3025 + 5333 + 7477) ;
你的公式是A00100除以N1字段之和的总和:)