简体   繁体   中英

Summarize a table with R

I am working on a dataframe...these are the first lane

           n      Sex área         perímetro  breed
1         54922    2 165.447       91.636       1
2         54922    2 295.479       85.899       1
3         54922    2  90.824       40.798       1
4         54922    2 385.859      110.012       1
5         54922    2  37.062       24.430       1
6         54922    2 189.638       87.498       1
7         54922    2  20.066       21.923       1
8         54923    2  19.807       23.540       1
9         54923    2 189.212       80.037       1
10        54923    2 342.065      110.022       1

I want to summarize this table by making mean of column 4and 5 (area and perimeter) by merging row of each repetition of the same individual (n). Can anybody suggest some function?

By merging, do you mean grouping by individual?

dplyr package:

library(dplyr)
df %>%
  group_by(n) %>%
    summarise(área = mean(área), 
              perímetro =mean(perímetro))

Output:

Source: local data frame [2 x 3]

      n     área perímetro
1 54922 169.1964  66.02800
2 54923 183.6947  71.19967

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM