In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use aggregate to group data processing, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
Use aggregate to group the data, including summation, mean, maximum, median and so on.
Aggregate is a powerful function. It first groups the data (by rows), and then performs functional statistics on each set of data. It has three uses according to the data object, which are applied to data boxes (data.frame), formulas (formula), and time series (ts) respectively:
Aggregate (x, by, FUN,..., simplify = TRUE) aggregate (formula, data, FUN,..., subset, na.action = na.omit) aggregate (x, nfrequency = 1, FUN = sum, ndeltat = 1, ts.eps = getOption ("ts.eps"),...)
For data grouping processing, for example, some data are as follows:
Dat ID sample1 sample2 sample3 type1 A 12 2 12 A 2 4 9 23 A 4 3 1 34 C 5 5 8 15 C 6 9 7 26 C 3 1 3 37 D 9 10 9 18 D 11 18 12
Group and sum the data according to type, mean or median, etc., take sum as an example:
> temp=aggregate (dat [, 2:4], by=list (dat$type), FUN=sum) > temp Group.1 sample1 sample2 sample31 1 15 17 192 2 19 31 173 3 7 4 4 >
The first parameter must be numeric, so the first column is removed, and the type is removed, and the resulting data Group.1 is the type type.
If you do it for both ID and type, the following results can be obtained:
> temp=aggregate (dat [, 2:4], by=list (dat$ID,dat$type) FUN=sum) > temp Group.1 Group.2 sample1 sample2 sample31 A 1 1 2 22 C 1 5 5 83 D 1 9 10 94 A 22 4 95 C 26 9 76 D 2 11 18 17 A 3 4 3 18 C 3 3 1 3
Mean, median, max and other operations are the same
Thank you for reading this article carefully. I hope the article "how to use aggregate to process data in groups" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.