我正在分析一段时间以来的议会数据,关于某一年妇女在议会中的百分比。有些年,由于妇女在议会中的百分比在这一年中经历了发展,因此有多种观察结果。因此,我想写一个代码,给我:
一段时间内某一年女性任职人数的平均数,然后按国家分组。
我的问题是,R不断返回NA值和一个警告,说我有非数值数据在我的数据集。然而,我似乎找不到这个非数值数据。我只有数字在百分比列。它可能是.在0.5给我的麻烦?
我尝试了以下代码在dqr:
Newlevelgenparla <- genparla %>%
group_by(Country, Year) %>%
summarize(Percent_women_in_parliament = mean(`Percent Of Women in Chamber`, na.rm = TRUE))
字符串
和
Newlevelgenparla <- genparla %>%
group_by(Year) %>%
summarize(Percent_women_in_parliament = mean(`Percent Of Women in Chamber`, na.rm = TRUE))
型
然而,后者也给了我NA,并没有按国家分组。所以这不是我要找的。
如果您能给我任何给予帮助,我将不胜感激!
编辑:dput(head(genparla))的输出:
structure(list(Country = c("Afghanistan", "Afghanistan", "Afghanistan",
"Afghanistan", "Afghanistan", "Afghanistan"), Region = c("ASIA",
"ASIA", "ASIA", "ASIA", "ASIA", "ASIA"), `Election / Renewal` = c("Yes",
"Yes", "Yes", "Yes", "Yes", "Yes"), Year = c(1965, 1965, 1969,
1969, 1988, 1988), Month = c("July", "July", NA, NA, NA, NA),
`Chamber Type` = c("Lower", "Upper", "Lower", "Upper", "Lower",
"Upper"), `Chamber Total Seats` = c("210", "84", "216", "84",
"235", "173"), `Total women` = c("4", "0", "0", "0", "7",
"0"), `Percent Of Women in Chamber` = c("0.019047619047619",
"0", "0", "0", "0.0297872340425532", "0"), NOTES = c("First legislature of Afghanistan after the abolition of the monarchy in 1964",
"First legislature of Afghanistan after the abolition of the monarchy in 1964",
"Parliament was dissolved following a military coup d'Etat in July 1973.",
"Parliament was dissolved following a military coup d'Etat in July 1973.",
"Collapse of constitutional institutions, including Parliament, in April 1992. A Council of Decision and Settlement or Constituent Assembly, comprising 1335 members met in December 1992 and January 1993 and elected from among its ranks a 250-member interim Assembly. Pending general elections: no available information concerning the number of women members of the Council or the interim Assembly.",
"Collapse of constitutional institutions, including Parliament, in April 1992. A Council of Decision and Settlement or Constituent Assembly, comprising 1335 members met in December 1992 and January 1993 and elected from among its ranks a 250-member interim Assembly. Pending general elections: no available information concerning the number of women members of the Council or the interim Assembly."
)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))
型
1条答案
按热度按时间jc3wubiy1#
基于你的dput,我能够复制这个问题,这是一个可以帮助你解决这个问题的解决方案.你需要首先将商会总席位,总妇女和商会中妇女的百分比转换为数字,因为它们是字符类型,然后执行你的摘要.你可以这样做与dapur:
字符串
然后,您可以执行汇总操作,现在两者都应该工作:
型