【发布时间】:2016-11-04 20:44:26
【问题描述】:
我的数据框主要包含分类列和一个数字列,df 看起来像这样(简化):
**Home_type** **Garden_type** **NaighbourhoOd** **Rent**
Vila big brooklyn 5000
Vila small bronx 7000
Condo shared Sillicon valley 2000
Appartment none brooklyn 500
Condo none bronx 1700
Appartment none Sillicon Valley 800
对于每个分类列,我想显示其所有不同的值、频率和与之相关的租金总和。
结果应该是这样的:
**Variable** **Distinct_values** **No_of-Occurences** **SUM_RENT**
Home_type Vila 2 12000
Home_type Condo 2 3700
Home_type Appartment 2 1300
Garden_type big 1 5000
Garden_type small 1 7000
Garden_type shared 1 2000
Garden_type none 3 3000
Naighbourhood brooklyn 2 5500
Naighbourhood Bronx 2 8700
Naighbourhood Sillicon Valley 2 2800
我是 R 的新手,并尝试在 reshape2 中使用 melt 来做到这一点,但没有取得多大成功,任何帮助将不胜感激。
【问题讨论】:
-
您可能需要查看this overview for asking good R questions,尤其是那些可以轻松读取数据的部分。如果我们不必费力地阅读您的数据,那么提供帮助会容易得多数据到 R.
-
谢谢你给我指点马克,我以后一定会更加小心,稍后会编辑这篇文章。
标签: r statistics reshape2