Count the first x integers of a group of values

DanDan4561

I want to get the count starting from 1, of the number of occurrences of Y until its subsequent value is N. A simple example table can be found below, I've added an additional column called expected output to highlight what I'm trying to achieve.

tab:([]x:`N`N`Y`N`N`Y`Y`Y`N`N`Y`Y`Y;expected_output:0 0 1 0 0 1 2 3 0 0 1 2 3)

I have been playing around with the idea of trying to use cut (granted that I can find the correct indexes) I could split the table up, get the count of each list, then piece it all back together somehow e.g.

0 2 3 5 8 10 cut tab
terrylynch

One approach using scan

q)update c:0{y*x+y}\x=`Y from tab
x expected_output c
-------------------
N 0               0
N 0               0
Y 1               1
N 0               0
N 0               0
Y 1               1
Y 2               2
Y 3               3
N 0               0
N 0               0
Y 1               1
Y 2               2
Y 3               3

Essentially a modified version of sums which resets the counter back to zero (using zero/false multiplication) whenever the next boolean is zero

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL: count rows where column = a value AND another column is the same as values in the group where the first condition is true?

From Dev

Group by count for boolean values in collection

From Dev

Group values by first value of group

From Python

Running count of repeating values by group

From Dev

Count the number of unique values by group

From Dev

Count total missing values by group?

From Dev

COUNT and COUNT, GROUP BY first count

From Dev

Count first consecutive matches on a group

From Dev

Pandas group by column and count values

From Dev

Mean of the first x values

From Dev

How to find grid neighbours (x, y as integers) group them and calculate mean of their values in spark

From Dev

MySQL GROUP BY with Zero values in the count

From Dev

count all values and group by with count

From Dev

Count and select first row by group

From Dev

How to count values in pandas group

From Dev

Count and group on occurrences of keys and their values

From Dev

Count(Distinct x) and Group By y

From Dev

Group by and count values

From Dev

Sum and count values by group

From Dev

Count distinct values depending on group

From Dev

How to count values in group by with condition?

From Dev

Count values that go in row in group?

From Dev

extract values based on first 4 integers

From Dev

MySQL Group by consecutive values and count

From Dev

Count all values in object where X is the first key letter

From Dev

Count unique values by group

From Dev

Count rows by group based on values

From Dev

R DPLYR Count Values BY Group

From Dev

EXCEL - count names per week - count row values X for all rows with value Y in the first cell

Related Related

HotTag

Archive