I would like to create the last column.Thank you in advance!
You could try something like this:
/*************************************/.
DATA LIST FREE /v1 v2 v3 v4 v5.
BEGIN DATA
1 2 99 4 5
99 2 3 99 5
1 99 3 4 5
1 2 99 99 5
1 99 99 99 5
99 2 99 99 99
END DATA.
DATASET NAME DS1.
/*************************************/.
/* Solution1: Assumes v1 to v5 can hold any value from 1 to 5 */.
recode v1 to v5 (99,sysmis=sysmis) (else=copy).
do repeat v=v1 to v5.
if (any(v,1,4,5)) Target1=1.
if (any(v,2,3)) Target2=2.
end repeat.
compute TargetA=sum(Target1,Target2).
/* Solution2: Alternative solution which assumes v1 holds values 1 only v2 values 2 only ect... */.
recode v1 to v5 (99,sysmis=sysmis) (else=1).
compute TargetB=sum(any(1,v1,v4,v5)*1, any(1,v2,v3)*2).
exe.
If I understand you correctly:
Your input file contains 5 columns, 1 per channel
Each channel-specific column is filled with channel-specific identifier (1-5)
When the column is empty, that channel is not used / not relevant for that observation
You want to summarize the mix of channels used in new field (NewVar)
You want to use the IF statement in the SPSS syntax
The answer above by JigneshSutar does not seem to do this. Also, you do not need the do-repeat-loops but can do this in 3 lines (+EXECUTE.) of syntax (using the data generator in the answer by JigneshSutar):
IF (V1 = 1 & V4 = 4 & V5 = 5) NewVar = 1.
IF (V2 = 2 & V3 = 3) NewVar = 2.
IF (V1 = 1 & V2 = 2 & V3 = 3 & V4 = 4 & V5 = 5) NewVar = 3.
EXECUTE.
This syntax can easily be adjusted when the channel columns are filled with other values than the channel identifiers [1-5], for instance by using the missing function:
IF (MISSING(V1)=0 & MISSING(V4)=0 & MISSING(V5)=0) NewVar = 1.
IF (MISSING(V2)=0 & MISSING(V3)=0) NewVar = 2.
IF (MISSING(V1)=0 & MISSING(V2)=0 & MISSING(V3)=0& MISSING(V4)=0 & MISSING(V5)=0) NewVar = 3.
EXECUTE.
Related
I have a constant number X. I also have two numbers that add up to it. How can I make it so that if I change one number, the other number automatically changes so that it still adds up to X.
I have tried to take subtract the one number from X and add it to the other number, but instead I got two numbers in the thousands.
Assuming your constant value is 10, you can set this in a cell and make all your other calculations based on it.
For example, you can have cell C2 containing your constant, in this example, 10
Then in C4 you can have the number which you change, and the value of C5 will be equal to the value of the constant minus the value in C4.
You can then finally do your sum wherever you want, adding up the values of C4 and C5.
Here's an example Spreadsheet:
Untitiled spreadsheet ☆
File Edit View Insert Format Data Tools Extensions Help Last edit was 2 minutes ago
↶ ↷ 🖶 ⮷ | 100%⯆ | $ % .0 .00 123⯆ | Default(Ro... ⯆ | 10 ⯆ | B | I | S | A |⯐|☰
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
1
2
Contsant:
10
3
4
Number 1:
3
5
Number 2:
=(C2 - C4)
6
7
Sum:
=(C4 + C5)
8
Example
3 2 5 5
a b c d
Joining first two
5 | 5 5
3 2 | c d
a b |
I have to put the new tree of five into the queue
Am I obligated to put it in the end like this:
5 5 5
c d / \
3 2
a b
Or can I put it in the beginning:
5 5 5
3 2 c d
a b
Or even in the middle of 'c' and 'd'
Is it my choice or is there a rule?
It's not your choice, the Queue needs to be sorted at all times (by it's number of occurrences and in case of equal number of occurrences by the depth of the tree). So it needs to be inserted where it belongs into the order.
This is needed to pick the sub-trees with the least amount of occurrences and if there is choice the most shallow one of them by simply pop-ing them.
If you simply resort after every insertion (this is inefficient and should not be done) the position obviously doesn't matter.
Yes, it's your choice. Whichever way you will get an optimal Huffman code, even though two resulting codes can be manifestly different.
You can get:
a - 00
b - 01
c - 10
d - 11
or you can get:
a - 111
b - 110
c - 10
d - 0
Now if I multiply the number of bits in each symbol times the number of occurrences, I get for the first code: 2*3 + 2*2 + 2*5 + 2*5 = 30 bits. For the second code: 3*3 + 3*2 + 2*5 + 1*5 = 30 bits. So both codes will code the original message to exactly 30 bits.
I've got a dataset with repeated measures that looks roughly like this:
ID v1 v2 v3 v4
1 3 4 2 NA
1 2 NA 6 7
2 4 3 6 4
2 NA 2 7 9
. . . . .
n . . . .
What I want to know is how many NAs are there for each participants over the variables v1 - v4 (e.g. participant 1 is missing 2 of 8 responses)?
Missing Values are always displayed per Variable not per participant so how do I do this? Maybe there is a way using the AGGREGATE command with ID as BREAK?
Use COUNT to count the missing values as a new variable and then aggregate by the Id or split files by I'd and freq.
I know that tensors have an apply method, but this only applies a function to each element. Is there an elegant way to do row-wise operations? For example, can I multiply each row by a different value?
Say
A =
1 2 3
4 5 6
7 8 9
and
B =
1
2
3
and I want to multiply each element in the ith row of A by the ith element of B to get
1 2 3
8 10 12
21 24 27
how would I do that?
See this link: Torch - Apply function over dimension
(Thanks to Alexander Lutsenko for providing it. I just moved it to the answer.)
One possibility is to expand B as follow:
1 1 1
2 2 2
3 3 3
[torch.DoubleTensor of size 3x3]
Then you can use element-wise multiplication directly:
local A = torch.Tensor{{1,2,3},{4,5,6},{7,8,9}}
local B = torch.Tensor{1,2,3}
local C = A:cmul(B:view(3,1):expand(3,3))
The data set is like this:
V1 V2 V3 V4 V5
x 1 2 n .
x 3 4 . .
x 5 6
If I want to calculate
V5 = V4 - V3
V4 = V5(previous line) + V2
How can I do it using syntax?
Use the LAG operator to access elements in the previous row.
DATA LIST FREE / V1 to V5.
BEGIN DATA
1 2 3 4 5
4 5 6 7 8
7 8 9 0 1
END DATA.
COMPUTE V5_2 = V4 - V3.
COMPUTE V4_2 = LAG(V5) + V2.