Questions tagged [summarize]

A dplyr instruction ( actually named summarise( ) ) to create a new data frame by grouping data according to given grouping variables. Use this tag along with the dplyr version being used. Mind the spelling in the method name.

summarise() creates a new data frame. It will have one (or more) rows for each combination of grouping variables; if there are no grouping variables, the output will have a single row (or more, as of 1.0.0) summarising all observations in the input. It will contain one column for each grouping variable and one column for each of the summary statistics that you have specified.

836 questions
0
votes
0 answers

Count unique values (factors) in a data.frame and return a summary

I have looked everywhere here in SO and did not find a solution. I am trying to create a summary of unique values (factors) of my data set. Consider this data: df <- structure(list(x = structure(c(3L, 4L, 1L, 5L, 2L, NA, NA), .Label = c("A", "H",…
bttomio
  • 2,206
  • 1
  • 6
  • 17
0
votes
1 answer

Error in applying summarise() function with across() in dplyr

I have two datasets, one consisting of data I have collected personally for individual specimens and the other consisting of mean data from previous studies reported in the literature. What I want to do is re-average the data combining the…
user2352714
  • 314
  • 1
  • 15
0
votes
3 answers

How to summarize(n=n()) with different filter()?

I want to print the following tables.enter image description here I tried several ways but I can only add one of the columns (either "to_ORD" or "to_MDW") with information of that type. How can I code to get them at the same time and on the same…
Jing Xu
  • 15
  • 2
0
votes
2 answers

Summarizing a collection of data frames - improving upon a clumsy solution

I have a collection of data frames, df_i, representing the ith visit of a set of patients to a hospital. I'd like to summarize each of the data frames to determine the number of men, women and total patients at the ith visit. While I can solve this,…
Thomas Philips
  • 935
  • 2
  • 11
  • 22
0
votes
1 answer

Iteratively summarise within a dplyr pipeline in R

Consider the following simple dplyr pipeline in R: df <- data.frame(group = rep(LETTERS[1:3],each=5), value = rnorm(15)) %>% group_by(group) %>% mutate(rank = rank(value, ties.method = 'min')) df %>% group_by(group) %>% summarise(mean_1…
Miguel
  • 416
  • 3
  • 16
0
votes
1 answer

Error while using dplyr::summarize with seq_along

An altruistic member here helped me write the following code to generate variables using a for loop and dplyr::summarize. This code, as expected, works fine. library(nycflights13) flights <- nycflights13::flights %>% …
Anup
  • 239
  • 2
  • 11
0
votes
1 answer

Why i can use this code for a group by in Rstudio

sexo fecha colnames 96991 Hombres 2020-03-02 sexo 96992 Hombres 2020-03-02 fecha 96993 Hombres 2020-03-02 sexo 96994 Hombres 2020-03-02 fecha 96995 Hombres 2020-03-02 sexo 96996 Hombres 2020-03-02 fecha I have…
javier
  • 15
  • 4
0
votes
1 answer

How do I use dplyr to correlate each column in a for loop?

I have a dataframe of 19 stocks, including the S&P500 (SPX), throughout time. I want to correlate each one of these stocks with the S&P for each month (Jan-Dec), making 18 x 12 = 216 different correlations, and store these in a list called…
Aneesh S
  • 1
  • 1
0
votes
1 answer

Use a specific column inside the user defined function for summarize function in dplyr

I have the following question. I have a dataset mtcars and I want to write a a function to summarize the given variable, e.g. mpg given that another variable has a particular value, e.g. vs = 1. I provide a code, where I want to summarize mpg given…
0
votes
0 answers

Summarize Unique Value

I have a data set of fantasy football stats that I am using to teach myself R. The data is annual player fantasy football Below is an example of the format it is in. | x | Year| Player | TM | *Pos*| Age |*FantasyPts*| | 1 | 2019| *J.Jones* |…
wmorse
  • 3
  • 3
0
votes
1 answer

Count unique matching items with filter as a calculated column

I have two tables are Data and Report. Data Table: In Data table contain three columns are Item, status, and filter. The item contains duplicated entry and the item column contains text and number or number only or text only. The status column…
johon
  • 65
  • 3
  • 12
0
votes
1 answer

Using summarise() to count the number of times the min value is repeated

I have this reach data frame with ordered values and Reachability and my desired output is a summary table of several properties grouped by Cluster. The entire table contains more values but I think 10 rows are more than enough to explain what I…
0
votes
0 answers

R function for aggregating count of loan numbers

loan_number date_component 2542 2020121604 2020-12-19 2544 2020121604 2020-12-19 2548 2020121604 2020-12-19 2557 2020121607 2020-12-19 2560 2020121607 2020-12-19 2563 2020121607 2020-12-19 I have data of loan…
0
votes
1 answer

PowerBi/Dax Summarize table and get average rating

I'm trying to create a new measure to find the average of the rating from my table, either the whole table or a particular 'id' as selected by a slicer. The issue is, in the original data if a user appears in more than one user group then they have…
user2134154
  • 7
  • 1
  • 4
0
votes
1 answer

Creating summary report from a matrix in R using vectorization

I want to create a summary table from a matrix. In the summary table, the first column has bins and subsequent columns are populated with frequencies based on certain conditions and width of bins. I have managed to do this using a for loop that…