logo
Tags down

shadow

R - filtering rows and summing


By : user84517
Date : October 14 2020, 02:23 PM
Hope this helps I have a data.table with multiple columns. I am trying to sum a subset of one particular column. , Here you go:
code :
library(data.table)
example_data[colName == 1 & colTarget == 1, sum(colName)]


Share : facebook icon twitter icon

Excel summing and filtering


By : aberope
Date : March 29 2020, 07:55 AM
will help you I have an excel sheet with 3 columns. , I solved it this way
code :
F2 = Jason
F3 = John
F4 = Mary
G2 (copied down) =SUMIFS($C$2:$C$15,$A$2:$A$15,$F2,$B$2:$B$15,"Cash")

H2 (copied down) =SUMIFS($C$2:$C$15,$A$2:$A$15,$F2,$B$2:$B$15,"Credit")

Access report summing data after the filtering


By : Luke
Date : March 29 2020, 07:55 AM
seems to work fine How do you specify the datasource to your report?
You may open the report this way...
code :
DoCmd.OpenReport "MyReport", acViewPreview, , "Id = " & MyId
DoCmd.OpenReport "MyReport", acViewPreview, , , , "Id = " & myId
.......
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = "Select fields from view where " & OpenArgs
End Sub

Filtering and summing rows in dplyr


By : mykar2un
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a data that I want to first filter some rows and sum those remaining rows.
code :
df_to_aggregate <- df %>% 
    group_by(gr) %>% 
    mutate(rows_to_aggregate = cumsum(y_value == 10)) %>% 
    filter(!(gr == 1 & rows_to_aggregate == max(rows_to_aggregate) & y_value != 10)) %>%
    filter(!(gr == 2 & rows_to_aggregate == 0)) %>%
    select(-rows_to_aggregate)
df_to_aggregate

# A tibble: 10 x 2
# Groups:   gr [2]
     gr y_value
  <dbl>   <dbl>
1     1       2
2     1      10
3     1      10
4     1       8
5     1      10
6     2      10
7     2      10
8     2       6
9     2       8
10    2      10

Summing a hidden column in DataTables after filtering


By : user2303632
Date : March 29 2020, 07:55 AM
Hope that helps Threw together a quick and dirty example to get you started. Basically, the table on 'draw' function will trigger on a search or filter event. From there you iterate through all of the visible filtered rows using this: { filter : 'applied'}
Run this snippet and search for "New York". Then check the console to see how the data and numbers behave.
code :
var mytable = new Object();

var tableData = [
    {name: 'Clark Kent', city: 'Metropolis', numCol: '10', numCol2: '6'},
    {name: 'Bruce Wayne', city: 'New York', numCol: '', numCol2: '12'},
    {name: 'Steve Rogers', city: 'New York', numCol: '30', numCol2: '10'},
    {name: 'Peter Parker', city: 'New York', numCol: '44', numCol2: ''},
    {name: 'Thor Odinson', city: 'Asgard', numCol: '55', numCol2: '15'}
	];

mytable = $('#mytable').DataTable({
    "search": {
        "regex": true
    },
	  sDom: 'lrftip',
    data: tableData,
    columns: [
    	{data: 'name', title: 'Name'},
    	{data: 'city', title: 'City'},
      {data: 'numCol', title: 'Number'},
      {data: 'numCol2', title: 'Hidden Num', visible: false}
    ], 
    columnDefs: [
        { className: "sum", "targets": [2] },
    ]
	});
  
   
mytable.on( 'draw', function () {
    console.log( 'Redraw occurred at: '+new Date().getTime() );
    var myCount = 0;
    var totalSum = 0;
    mytable.rows( { filter : 'applied'} ).every(function (rowIdx, tableLoop, rowLoop) {
            var data = this.data();
            
            console.log('num1: ' + data.numCol + ' num2: ' + data.numCol2);
            
            if (data.numCol !== '') {
            		//Add to counter                
                myCount += 1;
            }
            
            if (data.numCol2 !== '') {
            	//Sum it up	
              totalSum += parseInt(data.numCol2); 
            }
            
        });
        console.log('myCount: ' + myCount + ' totalSum: ' + totalSum);
} );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">

<div class="table-responsive">

<table id="mytable" class="table nowrap table-hover table-striped dataTable">
    <thead>
      <tr>
        <th>Name</th>
        <th>City</th>
        <th>Number1</th>
        <th>Number2</th>
      </tr>
    </thead>
    <tbody>
    </tbody>
    <tfoot id="mytableFoot">
      <tr>
        <th>Name</th>
        <th>City</th>
        <th>Number1</th>
        <th>Number2</th>
      </tr>
    </tfoot>
  </table>
</div>

Summing a column after filtering Django 2.1


By : absoute_20
Date : March 29 2020, 07:55 AM
should help you out Doing it in JS would be fine, but IMO passing it through the context from the view is better. JS is much harder to do tests for.
If you use Jinja templates (really easy to set up and to use), you could use their filters:
Related Posts Related Posts :
  • Get the min value of one variable greater than the observation of another variable
  • Reference previous value in data.table calculation
  • 'Can't create call to non-callable object' error while summarizing data by grouping
  • Multiplying all columns in dataframe by single column
  • Calculating Standard Deviation by each unique variable in R.
  • Fisher exact test for each gene
  • Sorting coordinates to create a polygon gives messy results
  • Merging legends in ggplot fails with certain expressions
  • Shiny modal dialog in response to multiple buttons
  • Error connecting to mongoDB using Mongolite
  • R: networkD3 sankey plot - colours not displaying
  • Merging two rows into one header using R
  • Parse JSON to dataframe returns different numbers
  • How to number by group?
  • Multinomial probit regression with mixed type explanatory variables
  • How can I make a variable in a dataset containing a vector of all numbers between two other variables?
  • How to extract the trailing digits from a string in R?
  • Select values based on other columns
  • readLines killing R in purrr::map
  • Subset rows based on "start and stop" strings
  • How to add a column to lists within a list without losing their names?
  • Plotting the means in ggplot, without using stat_summary()
  • R :Looping through each 5 rows of data frame and imputing incremental value
  • In R, is growing a list just as inefficient as growing a vector?
  • Flexdashboard, rhandsontable: how to programmatically access user updated table?
  • Creating Summary Table from R Variables
  • Average over groups and include previous groups
  • R: data.table count rows on specific columns > 0
  • Transform (shuffle) just 2 Fields in a Dataframe
  • Issue with replacing string by match in R
  • (very) Simple quantstrat trading model using logistic regression
  • R - count maximum number of consecutive dates
  • Problems using tidyr separate on "|"
  • Default value when calling a function in a for loop
  • Finding values in a matrix from list of values in R
  • count 0's in a zoo (or dataframe) object
  • Finding the first non-zero year in data frame for multiple variables using tidyverse
  • ggplot2 - how to assign geom_text with arrow icon to second yaxis scale
  • regex fails with dollar sign
  • Drop first element of list of lists, condense list of lists? Too many elements?
  • R - how to apply output of ifelse(str_detect ...) to whole group
  • caret package confusion matrix define positive case with multiple classes
  • Generating a pairwise 'distance' matrix
  • Change all R columns names using a reference file
  • In R & dabestr, how do I get grouped differences correctly?
  • Exclude or set a unique color to the bottom triangle of a correlation matrix heatmap
  • r shiny observe function clears text input
  • Split column by multiple delimiters, keeping delimiters
  • How to random search in a specified grid in caret package?
  • merge 2 data frames in a loop for each column in one of them
  • how to edit the codes for the summary of R S4 Object?
  • Remove specific rows in R
  • Flatten JSON list into data frame
  • Filtering a dataset and making a ggplot
  • Align cells vertically to be at the bottom flextable
  • R speed up sapply
  • invalid subscript type 'list' Azure Machine Learning
  • Use rollapply with xts object and an anonymous defined function
  • Isolate data frames from a spreadsheet to create a list
  • Error in xts, as.POSIXct "'order.by' cannot contain 'NA', 'NaN', or 'Inf'"
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org