几周前我刚刚开始捡起R。我在尝试转换时遇到了一些问题(如果这是正确的R术语?)性别行到列。DPLYR突变函数“transmute”?
> brfss %>%
+ filter(hours1 >=1,hours1 <=24) %>%
+ group_by(hours1, gender) %>%
+ summarise(count = n())
# A tibble: 48 x 3
# Groups: hours1 [?]
hours1 gender count
<int> <fctr> <int>
1 1 Male 96
2 1 Female 132
3 2 Male 464
4 2 Female 612
5 3 Male 1433
6 3 Female 2063
7 4 Male 5749
8 4 Female 8512
9 5 Male 13231
10 5 Female 20205
# ... with 38 more rows
我想作为显示列:
hours1 Male Female count
基本上能够把最全男/女列,而不是行。有人能给我一些指点吗?谢谢。
可能重复的[R如何创建数据透视表的数据框,同时涉及3个变量?](https://stackoverflow.com/questions/11597542/r-how-to-create-pivot- table-like-data-frame-while-3-variables-are-involved) – Psidom
^^回答你的q @ junha082? – hrbrmstr
感谢您的回复,我已经检查过这个帖子,其实并不是要获得某个值的平均值(我可能会使用transmute/summarize),而是将整个性别从一行转换为一列。但让我谷歌Dcast从reshape2 – junhao82