官术网_书友最值得收藏!

  • Hands-On Data Science with R
  • Vitor Bianchi Lanzetta Nataraj Dasgupta Ricardo Anjoleto Farias
  • 138字
  • 2021-06-10 19:12:37

Summarise

The summarise verb is used to obtain aggregate values, generally over a grouped variable.

The following highlights some of the common operations using summarise. Generally, summarise is preceded by a group_by operation, that is, the summary is performed over grouped variables, as shown:

# In the example below: 
# 1) We sorted the DataFrame by State Name using arrange 
# 2) We applied a group-by using Region, i.e., all resulting values would be aggregated using Region 
# 3) We calcuated the values for total rows using n(), the unique states belonging to each region using n_distinct 
#   the max & mean literacy using max and mean respectively 
#  
 
tstate %>% arrange(Name) %>% group_by(Region) %>%  
  summarise(total_rows = n(), first_state = first(Name),  
unique_states = n_distinct(Name), max_literacy = max(100-Illiteracy), mean_literacy = mean(100-Illiteracy, na.rm=T)) 

The output is as follows:

主站蜘蛛池模板: 衡阳市| 高陵县| 新巴尔虎右旗| 上思县| 高邮市| 宜昌市| 孙吴县| 十堰市| 阆中市| 米易县| 宁夏| 永新县| 株洲县| 宜兴市| 方正县| 闻喜县| 陵川县| 康保县| 巴青县| 韶山市| 延庆县| 牡丹江市| 天津市| 梁山县| 历史| 兴安县| 商水县| 沈阳市| 高州市| 五台县| 来凤县| 毕节市| 淮滨县| 历史| 井冈山市| 兴仁县| 永靖县| 农安县| 菏泽市| 丹凤县| 保亭|