probably very simple question but yeah, dont know how of course.
I have 3 columns:
A B C
-------
5 1 A
5 2 B
5 3 C
and want to multiply column A and B, and just copy C column. All with one expresion.
So Result of multiplication A and B should be in D and result of copying should be in F:
Final result should be:
D F
---
5 A
10 B
15 C
Is there any simple method to do something like this?
this should do:
=INDEX({A1:A3*B1:B3, C1:C3})
or if you are on non-english sheet:
=INDEX({A1:A3*B1:B3\ C1:C3})
Related
I have a sheet the the followin info
"A" "B"
_____
a 1
a 1
a 1
a 1
a 1
a 1
b 1
b 1
b 0
b 1
b 1
b 1
c 1
c 0
c 1
d 1
d 1
I Like to have an Array formula that multiplies al values on column "B" that have the same text on column "A"
I don't whant to use a pivot table, i need to solve this with formulas.
End result should be on column "C"
a = 1
b = 0
c = 0
d = 1
thanks
I can do it in two columns....
Column C formula
=IF(A3=A2,C3*B2,B2)
Column D formula
=IF(A2<>A1,CONCATENATE(A2," = ",C2),"")
gives results like this
Excel image
if the blanks are a problem,
http://www.cpearson.com/excel/NoBlanks.aspx
DPRODUCT() might do it, as well, if you can setup the criteria correctly.
OK i solved using this formula as array
=+SI(SUMA(SI((A:A=A1);B:B;0))=CONTAR.SI(A:A;A1);"OK";"")
I am studying data structures right now and in specific Hash Tables. I came across the follow question:
Imagine that we have placed the following keys
in an initial empty hash table with a length of 7
with linear probing, using the following table of hash-values:
key: A B C D E F G
hash: 3 1 4 1 5 2 5
Which of the following arrays could be the linear-probing array?
1.
0 1 2 3 4 5 6
G B D F A C E
2.
0 1 2 3 4 5 6
B G D F A C E
3.
0 1 2 3 4 5 6
E G F A B C D
When I create the linear-probing array I get this:
0 1 2 3 4 5 6
G B D A C E F
Could somebody please tell me why I am wrong and whats the right answer?
Notice how the question doesn't specify the order in which the keys are inserted, so your answer is only correct assuming that the keys are actually inserted in the order A-B-C-D-E-F-G, but since the question doesn't explicitly state the order, you need to dig deeper.
What you do know, however, is that one of those keys will be inserted first and it will go to its designated slot as shown in the Key-to-Hash diagram, since the hash table is initially empty. This immediately discards option choice 2 because none of the keys are in their designated array entry, leaving you with choice 1 and 3.
For table 1, B is in slot 1, which corresponds to its hash value and for table 3, keys F and A are in their initial hash-value spots.
It's simple to prove that no sequence of key inserts on table 3 after inserting F and A will yield table 3 as a result. And its likewise easy to prove that the sequence of key inserts B-D-F-A-C-E-G will result in table 1.
Although this is a question based on hash tables, I honestly don't consider it a good way to assess your knowledge on linear probing, this is more of a puzzle, as #gnasher729 mentioned.
I can't seem to find something quite like this problem...
I have an array table where each row contains a random assortment of numbers 1-N
On another sheet, I have a table with column and row headers numbered 1-N
I want to count how many rows in the array contain both the column and row headers for a given cell in the table. Since countifs only reference the current cell in the specified array, they don't seem to be working in this scenario.
Example array:
A B C D
1 3 5 7
1 2 3 4
2 3 4 5
2 4 6 8
...
Table results (symmetrical about the diagonal):
A B C D E F
. 1 2 3 4 5 ...
1 - 1 2 1 1
2 1 - 2 2 1
3 2 2 - 2 2
4 1 2 2 - 1
5 1 1 2 1 -
Would using nested countifs work?
I don't agree with your results corresponding to 4/2, which surely should be 3, not 2, but this formula, based on the array table being in Sheet1 A1:D4 and the results table being in Sheet2 A1:F6, placed in cell B2 of the latter, should work:
=IF($A2=B$1,"-",SUMPRODUCT(N(MMULT(N(COUNTIF(OFFSET(Sheet1!$A$1:$D$1,ROW(Sheet1!$A$1:$D$4)-MIN(ROW(Sheet1!$A$1:$D$4)),),CHOOSE({1,2},B$1,$A2))>0),{1;1})=2)))
Copy across and down as required.
Note: If your actual table is in fact much larger than that given, it will probably be worth adding a simple clause into the above to the effect that the results for approximately half of the cells are obtained from their symmetrical counterparts, rather than via calculation of this construction, thus saving resource.
Regards
I have a matrix with n rows and 3 columns, and I should multiply row n column 2 with row n column 3.
So if I have a matrix that looks like this:
1 2 3
4 5 6
7 8 9
Then I should multiply 2 with 3, 5 with 6 and 8 with 9, and create a matrix or an array that holds results:
6
30
72
How can I do that in C?
Since you are interested in learning C, an outline should do :-) The output is going to be a single column vector. Input to your function is a matrix, of some dimension p x q, and two column numbers c1 and c2. You can not skin it at least two ways.
a function that does exactly what your problem asks, iterating x[1..p][c1] and x[1..p][c2] (so loop variable will be row numbers 1..p, and multiply them, producing result[1..p]
a function that returns a column vector from a given matrix, and then another function that does the element-wise product of two vectors as above. This jimho might be a more interesting option.
HTH
I'm working in R and I'd like to call a selection of values from a data frame by their column and row indices. However doing this yields a matrix rather than an array. I shall demonstrate:
Given the data.frame:
a = data.frame( a = array(c(1,2,3,4,5,6,7,8,9), c(3,3)) )
(for those of you who don't want to plug it in, it looks like this)
a.1 a.2 a.3
1 1 4 7
2 2 5 8
3 3 6 9
And lets say I have two arrays pointing to the values I'd like to grab
grab_row = c(3,1,2)
grab_col = c(1,2,1)
Now I'd expect this to be the code I want...
a[ grab_row, grab_col ]
To get these results...
[1] 3 4 2
But that comes out as a 3x3 matrix, which makes enough sense in and of itself
a.1 a.2 a.1.1
3 3 6 3
1 1 4 1
2 2 5 2
Alright, I also see my answer is in the diagonal of the 3x3 matrix... but I'd really rather stick to an array as the output.
Any thoughts? Danka.
Passing the row and column indices in as a two-column matrix (here constructed using cbind()) will get you the elements you were expecting:
a[cbind(grab_row, grab_col)]
[1] 3 4 2
This form of indexing is documented in ?"[":
Matrices and array:
[...snip...]
A third form of indexing is via a numeric matrix with the one
column for each dimension: each row of the index matrix then
selects a single element of the array, and the result is a vector.
Try this:
> mapply(function(i,j)a[i,j], grab_row, grab_col)
[1] 3 4 2
Works for both dataframes and matrices.