I want to sum using IF condition in SPSS - spss

I am looking for sum if syntax in SPSS. I have 3 variable. UUID is repeted here. I want to sum the server count for each UUID (ex:68d92 )and Virt flag P. I want syntax in SPSS. How can I do this?
server_conunt `UUID` `virt_flag` `P count (excel formula)` ANswer
1 68d92 P '=SUMIFS([server_count],[uuid],[#uuid],[virt_flag],"P") 13
1 68d92 P
1 68d92 HP
6 68d92 P
1 68d92 P
1 68d92 Hp
1 68d92 P
1 68d92 P
1 af8b1 P 7
1 af8b1 Hp
2 af8b1 P
1 af8b1 Hp
1 af8b1 P

Use a temporary SELECT IF for the condition and AGGREGATE to get the counts in either a new dataset or attached to each case. For example, to append to existing cases,
temporary.
select if virt_flag eq 'P'.
aggregate /outfile=* mode=addvariables
/break UUID
/sum_server_conunt = sum(server_conunt).

Related

Find the row of highest numbers from each of names or group who'd has been have a some of similarity of names then sumif their values group of names

I want to make the total of values every each member or names in every each their own group at the first match (or after blank space) or highest values positions of each them on column "D" according to column "B" with the result's row of an output like the exactly as an EXPECT OUTPUT as act of what I've just created on column "E". That's the replace a little bit down of just only one row from the column "B" positions or row must be the same as the column "C" and "D". Could we do this anyway ?
My achievements: I feel I've tried this before and got succeed to achieve this but I've forgot how to solve this when that happened. But it's look like kinda this code of formula:
=FILTER(IF(IFERROR(MATCH($B$3:$B;$B:$B;0);0)=ROW($B$3:$B);SUMIF($B$3:$B;$B$3:$B;$D$3:$D);"");$B$3:$B<>"0")
I don't know if I'm right or wrong but please see the table I'd created at the down below this and also see how I expected with that and feel free as well to edit to my doc file of google sheet I attached down below this.
THIS HERE YOU CAN EDIT TO MY SAMPLE G.SHEET TO SOLVE THIS MY QUIZ. THANKS IN ADVANCE!
A
B
C
D
E
1
2
N U M B
I D   -   M E M B E R
I D      -     C O D E
V A L U E S
E X P E C T     O U T P U T
3
4
4
JYFI7
5
JYFI7
J3573
3
6
6
JYFI7
IYR
1
7
JYFI7
F498S
2
8
9
3
DFJ9F11
10
DFJ9F11
C684J
7
8
11
DFJ9F11
J58
1
12
13
2
H684K
14
H684K
JF585
2
2
15
16
1
FJSR
17
FJSR
4684
7
16
18
FJSR
834
1
19
FJSR
49
2
20
FJSR
9835
6
Here's a possible solution:
=ARRAYFORMULA(LAMBDA(cusum,IF(SCAN(,cusum,
LAMBDA(acc,cur,if(cur="",,acc+1)))=1,cusum,))
(SORT(SCAN(,SORT(D3:D,ROW(D3:D),0),
LAMBDA(acc,cur,if(cur="",,acc+cur))),ROW(D3:D),0)))
You can find it in tab 'z' cell F3.

Performing a one to many join in R dplyr

How to do a one to one-to-many join without any keysin r using dplyr?
I have two tables:
origin<-tribble(~"o",
1,2)
destination<-tribble(~"d",
5,
6,
7)
I want to merge both of them without any keys like the following:
od<- tribble(~"o",~"d",
1,5,
1,6,
1,7,
2,5,
2,6,
2,7)
Can anyone help me out with this?
You can use slice and rep to repeat the rows in origin based on the length of destination. Then, inside of bind_cols, we can create a list and repeat the values in destination based on the length of origin; then, bind them together.
library(tidyverse)
origin %>%
slice(rep(1:n(), each = nrow(destination[, 1]))) %>%
bind_cols(., d = unlist(rep(
c(destination[, 1]), times = nrow(origin)
)))
Output
# A tibble: 6 × 2
o d
<dbl> <dbl>
1 1 5
2 1 6
3 1 7
4 2 5
5 2 6
6 2 7
tidyr::crossing and expand_grid can give you a cross join of two dataframes.
tidyr::crossing(origin, destination)
#tidyr::expand_grid(origin, destination)
# o d
# <dbl> <dbl>
#1 1 5
#2 1 6
#3 1 7
#4 2 5
#5 2 6
#6 2 7

How to average of last days data in influxdb

I want to calculate the average of unit_price from entries of the last known day from my influxdb database.
Below shows you the last two days data I have (14 entries per day)
I have 5 different days data in total.
> select * from "variable" order by time desc limit 28
name: variable
time area_code area_name unit_price
---- --------- --------- ----------
2021-05-11T23:00:00Z P Northern_Scotland 18.4695
2021-05-11T23:00:00Z N Southern_Scotland 17.598
2021-05-11T23:00:00Z M Yorkshire 16.968
2021-05-11T23:00:00Z L South_Western_England 18.6795
2021-05-11T23:00:00Z K Southern_Wales 18.081
2021-05-11T23:00:00Z J South_Eastern_England 18.501
2021-05-11T23:00:00Z H Southern_England 17.5875
2021-05-11T23:00:00Z G North_Western_England 17.4615
2021-05-11T23:00:00Z F North_Eastern_England 17.262
2021-05-11T23:00:00Z E West_Midlands 17.6085
2021-05-11T23:00:00Z D Merseyside_and_Northern_Wales 19.4355
2021-05-11T23:00:00Z C London 17.4405
2021-05-11T23:00:00Z B East_Midlands 17.3565
2021-05-11T23:00:00Z A Eastern_England 17.871
2020-11-01T00:00:00Z P Northern_Scotland 17.073
2020-11-01T00:00:00Z N Southern_Scotland 16.2225
2020-11-01T00:00:00Z M Yorkshire 15.6135
2020-11-01T00:00:00Z L South_Western_England 17.094
2020-11-01T00:00:00Z K Southern_Wales 16.527
2020-11-01T00:00:00Z J South_Eastern_England 16.8945
2020-11-01T00:00:00Z H Southern_England 16.128
2020-11-01T00:00:00Z G North_Western_England 16.0125
2020-11-01T00:00:00Z F North_Eastern_England 15.7395
2020-11-01T00:00:00Z E West_Midlands 16.086
2020-11-01T00:00:00Z D Merseyside_and_Northern_Wales 17.8605
2020-11-01T00:00:00Z C London 15.897
2020-11-01T00:00:00Z B East_Midlands 15.8445
2020-11-01T00:00:00Z A Eastern_England 16.2855
As you can see here, limit 14 average shows the same result as not using limit at all.
So this mean command is averaging 'all' the data, not any limited data.
select mean(unit_price) from "variable" order by time desc limit 14
name: variable
time mean
---- ----
1970-01-01T00:00:00Z 16.2924375
> select mean(unit_price) from "variable"
name: variable
time mean
---- ----
1970-01-01T00:00:00Z 16.2924375
>
I have tried nested selects, but can’t seem to find how to get an average of the final 14 entries (or from the final date with data)
Any help would be very much appreciated.
Think I may have solved with after playing some more with nested queries.
> select mean(unit_price) from "variable" group by time(1d) fill(none)
name: variable
time mean
---- ----
2019-04-12T00:00:00Z 15.572249999999997
2020-01-15T00:00:00Z 15.340499999999997
2020-11-01T00:00:00Z 16.377
2021-05-11T00:00:00Z 17.880000000000003
> select last("mean") from (select mean(unit_price) from "variable" group by time(1d) fill(none))
name: variable
time last
---- ----
2021-05-11T00:00:00Z 17.880000000000003
>

Octave Conditional Merging of matrices

I have searched for an Octave function that facilitates conditional merging of matrices but haven't one so far. My goal is to do this using vectors without looping. Here is an example of what I am trying to do.
A= [1 1
2 2
3 1
5 2];
B= [1 9
2 10];
I would like to get C as
C= [1 1 9
2 2 10
3 1 9
5 2 10];
Is there a function that takes A, B and the list of column(s) to join on and then produce C?
You can use the second output of ismember to find the occurrences of the second column of A in the first column of B and then use that to grab specific entries from the second column of B to construct C.
[~, inds] = ismember(A(:,2), B(:,1));
C = [A, B(inds,2)];
%// 1 1 9
%// 2 2 10
%// 3 1 9
%// 5 2 10

Quick way to determine the number of k-length paths from A to B in a dense complete graph

Given a complete dense graph (over 250.000 nodes) , what is the quickest way to determine the number of k-length paths from node A to B ?
I understand this is an old post, but I had the exact same question and could not find the answer.
I like to think of this problem as a "permutation without repetition", as the order of the nodes visited matters (permutation) and we aren't backtracking (no repetitions). The number of permutations without repetition is: n!/(n-r)!
For a complete graph with N nodes, there are N - 2 remaining nodes to choose from when creating a path between a given A and B. To create a path of length K, K-1 nodes must be chosen from the remaining nodes after A and B are excluded. Therefore, in this context, n = N - 2, and r = k - 1.
Plugging into the above formula yields:
(N-2)!/(N-K-1)!
Example: for N = 5, with nodes 0,1,2,3,4 the following paths are possible from 0 to 1:
0 1
0 2 1
0 2 3 1
0 2 3 4 1
0 2 4 1
0 2 4 3 1
0 3 1
0 3 2 1
0 3 2 4 1
0 3 4 1
0 3 4 2 1
0 4 1
0 4 2 1
0 4 2 3 1
0 4 3 1
0 4 3 2 1
This yields 1 path of length 1, 3 paths of length 2, 6 paths of length 3, and 6 paths of length 4.
This appears to work for any N>=2 and K<=N-1.
You can use basically dynamic programming: For each node Y and path length k, you can compute the number of paths from A to Y of length k if you know the number of paths from A to X of path length k-1 for all nodes X. Total complexity is O(KV), where K is the total path length you are trying to compute for and V is the number of vertices.

Resources