Linked Questions

223 votes
8 answers
690k views

Mean per group in a data.frame [duplicate]

I have a data.frame and I need to calculate the mean per group (i.e. per Month, below). Name Month Rate1 Rate2 Aira 1 12 23 Aira 2 18 73 Aira 3 ...
Ianthe's user avatar
  • 5,639
192 votes
5 answers
309k views

Summarizing multiple columns with dplyr? [duplicate]

I'm struggling a bit with the dplyr-syntax. I have a data frame with different variables and one grouping variable. Now I want to calculate the mean for each column within each group, using dplyr in R....
Daniel's user avatar
  • 7,612
80 votes
2 answers
43k views

Can dplyr summarise over several variables without listing each one? [duplicate]

dplyr is amazingly fast, but I wonder if I'm missing something: is it possible summarise over several variables. For example: library(dplyr) library(reshape2) df <- data.frame( sex = factor(rep(...
David F's user avatar
  • 1,526
56 votes
2 answers
192k views

Aggregate multiple columns at once [duplicate]

I have a data-frame likeso: x <- id1 id2 val1 val2 val3 val4 1 a x 1 9 2 a x 2 4 3 a y 3 5 4 a y 4 9 5 b x 1 7 6 b y 4 4 7 b x ...
Rookie's user avatar
  • 5,319
10 votes
3 answers
26k views

Means multiple columns by multiple groups [duplicate]

I am trying to find the means, not including NAs, for multiple columns withing a dataframe by multiple groups airquality <- data.frame(City = c("CityA", "CityA","CityA", ...
Jen's user avatar
  • 203
9 votes
1 answer
11k views

How to apply summarise_each to all columns except one? [duplicate]

I am analyzing a set of data with many columns (almost 30 columns). I want to group data based on two columns and apply sum and mean functions to all the columns except timestamp. How would I use ...
Behrad3d's user avatar
  • 439
7 votes
2 answers
17k views

Summing all columns by group [duplicate]

I'm positive that this is an incredibly easy answer but I can't seem to get my head around aggregating or casting with Multiple conditions I have a table that looks like this: > head(df, n=10L) ...
NoobMat's user avatar
  • 93
-1 votes
2 answers
29k views

R - Aggregate (sum) totals for grouped data using dplyr [duplicate]

I have a large dataset containing the names of hospitals, the hospital groups and then the number of presenting patients by month. I'm trying to use dplyr to create a summary that contains the total ...
Greg Martin's user avatar
4 votes
3 answers
12k views

Aggregating rows for multiple columns in R [duplicate]

I have a df that basically looks like this: Id A B C total 3 5 0 1 6 3 4 3 4 11 3 2 1 2 5 4 5 4 3 12 4 3 2 4 9 4 1 1 1 3 I want ...
user3315563's user avatar
3 votes
3 answers
11k views

Summary stats by factor level for multiple variables [duplicate]

I want to produce dataframes containing summary statistics for each factor level for multiple variables. For example if I have the following dataframe Factor <- c("A","A","A","B","B","B") ...
Rory Shaw's user avatar
  • 851
3 votes
2 answers
6k views

Percentage group by for multiple columns in R dataframe [duplicate]

I have a dataframe structure like below: No A B C D Group ========================= 1 2 3 1 4 GA 2 4 5 3 1 GA 3 8 6 1 3 GA 4 6 1 3 ...
Bharata's user avatar
  • 725
3 votes
2 answers
6k views

Summing columns on every nth row of a data frame in R [duplicate]

I have data frame with 12511 rows and 16 columns obtained from animal running experiment. Each row representing running counts every minute for each animal. I would like to sum the columns on every ...
henok's user avatar
  • 33
-1 votes
1 answer
9k views

How to combine duplicate rows in a data frame in R [duplicate]

Given a dataframe (my_data) in R such as the following category Keyword1 Keyword2 Keyword3 Keyword4 Keyword5 Keyword6 Keyword7 Keyword8 123 0 1 1 0 0 0 ...
Yamane Imad's user avatar
2 votes
1 answer
3k views

Summarise multiple columns using dplyr R [duplicate]

Let's say I have this dataframe: Agency Submissions Population County 1 36 1500 Jackson 2 0 800 Jackson 3 12 1400 ...
DiamondJoe12's user avatar
  • 1,921
3 votes
3 answers
1k views

How to select columns to work with median function in dplyr? [duplicate]

I have the following data set: df <- tribble( ~id, ~name, ~day_1, ~day_2, ~day_3, ~day_4, ~rank, "101", "a", 5, 2, 1, 8, '1', "202", "b", 8, 4, ...
datazang's user avatar
  • 1,069

15 30 50 per page
1
2 3 4 5
16