I am new to tableau 10. I have two class variables say A and B entered in rows at the top of my worksheet. What I want is the count of A and B (in statistics we call A*B an interaction). I want the number of rows with A and B attributes.
Thanks.
Mary A Marion
This can be achieved with the help of Sets in Tableau or using a Filter. I will explain the procedure for both with this sample dataset.
+--------+--------+------+
| ClassA | ClassB | Name |
+--------+--------+------+
| 1 | 1 | Abc |
| 0 | 0 | Def |
| 0 | 1 | Ghi |
| 0 | 1 | Jkl |
| 0 | 1 | Mno |
| 1 | 0 | Pqr |
| 1 | 0 | Stu |
| 1 | 0 | Vwx |
| 1 | 1 | yz |
+--------+--------+------+
Set - We create a set from name the 'Name' field as shown below
We should create the set based on a condition. When ClassA = 1 AND ClassB = 1. We do that as shown below. I am naming the set with the default name 'Set 1'
Now, drag 'Set 1' and 'Number of Records' to the rows. We would get something as shown below.
This can be read as 2 member are in the set, while 7 do not satisfy the condition and are out of the set.
Filter - Add ClassA and ClassB to the filter and select the values you want to see. Below is the screenshot of the output of adding a filter
Hope this helps!
Related
I have a database that I don't control the source of directly and results in errant '0' entries which mess up generated graphs with these drops to zero. I am able to manipulate the data after the fact and update that database.
It is acceptable that the last known good value can be used instead and so I am trying to make a general query that will remove all the zeros and populate it with the last known value.
Luckily, every entry includes the ID of the last entry and so it is a matter of simply looking back and grabbing it.
I have got very close to a final answer, but instead of updating with the last good value, it just uses the first value over and over again.
dummy data
CREATE TABLE tbl(id INT,r INT,oid INT);
INSERT INTO tbl VALUES(1,10,0);
INSERT INTO tbl VALUES(2,20,1);
INSERT INTO tbl VALUES(3,0,2);
INSERT INTO tbl VALUES(4,40,3);
INSERT INTO tbl VALUES(5,50,4);
INSERT INTO tbl VALUES(6,0,5);
INSERT INTO tbl VALUES(7,70,6);
INSERT INTO tbl VALUES(8,80,7);
SELECT * FROM tbl;
OUTPUT:
| id| r |oid|
|---|----|---|
| 1 | 10 | 0 |
| 2 | 20 | 1 |
| 3 | 0 | 2 | ** NEEDS FIXING
| 4 | 40 | 3 |
| 5 | 50 | 4 |
| 6 | 0 | 5 | ** NEEDS UPDATE
| 7 | 70 | 6 |
| 8 | 80 | 7 |
I have worked several queries to get results around what I am after:
All zero entries:
SELECT * FROM tbl WHERE r = 0;
OUTPUT:
| id | r | oid |
|----|----|-----|
| 3 | 0 | 2 |
| 6 | 0 | 5 |
Output only the those rows with the preceding good row
SELECT * FROM tbl WHERE A in (
SELECT id FROM tbl WHERE r = 0
UNION
SELECT oid FROM tbl WHERE r = 0
)
OUTPUT:
| id| r |oid|
|---|----|---|
| 2 | 20 | 1 |
| 3 | 0 | 2 |
| 5 | 50 | 4 |
| 6 | 0 | 5 |
Almost works
This is as close as I have got, it does change all the zero's, but it changes them all to the value of the first lookup
UPDATE tbl
SET r = (SELECT r
FROM tbl
WHERE id in (SELECT oid
FROM tbl
WHERE r = 0)
) WHERE r = 0 ;
OUTPUT:
| id| r |oid|
|---|----|---|
| 1 | 10 | 0 |
| 2 | 20 | 1 |
| 3 | 20 | 2 | ** GOOD
| 4 | 40 | 3 |
| 5 | 50 | 4 |
| 6 | 20 | 5 | ** BAD, should be 50
| 7 | 70 | 6 |
| 8 | 80 | 7 |
If it helps, I created this fiddle here that I've been playing with:
http://sqlfiddle.com/#!5/8afff/1
For this sample data all you have to do is use the correct correlated subquery that returns the value of r from the row with id equal to the current oid in the WHERE clause:
UPDATE tbl AS t
SET r = (SELECT tt.r FROM tbl tt WHERE tt.id = t.oid)
WHERE t.r = 0;
See the demo.
I've a data table like this
+------------+-------+
| Model | Price |
+------------+-------+
| Apple-1 | 10 |
+------------+-------+
| New Apple | 11 |
+------------+-------+
| Orange | 13 |
+------------+-------+
| Orange2019| 15 |
+------------+-------+
| Cat | 19 |
+------------+-------+
I'want to define a list of base model tags that I want to add to any single row that matches certain condition/value. So for example defined a data frame for tagging like this
+------------+--------+
| Model | Tag |
+------------+------ -+
| Apple-1 | A |
+------------+------ -+
| New Apple | A |
+------------+------ -+
| Orange | B |
+------------+------ -+
| Cat | B |
+------------+--------+
I would like to find some way to get this results:
+------------+-------+--------+
| Model | Price | Tag |
+------------+-------+--------+
| Apple-1 | 10 | A |
+------------+-------+--------|
| New Apple | 11 | A |
+------------+-------+--------|
| Orange | 13 | B |
+------------+-------+--------|
| Orange2019| 15 | B |
+------------+-------+--------|
| Cat | 19 | B |
+------------+-------+--------|
I'm don't mind to use a table to managed the tagging data, and I know that I could write very "ad-hoc" mutate statement to achieve the results I want, just wondering if there is more elegant way to tagging a string based on a pattern match.
One idea is to use the Levenshtein distances to cluster the words you have. You would need to provide with a number of clusters. Once you have this clusters, just add the number of each one as a category tag to your table. Check out this answer which goes into detail of Levenshtein distance clustering. Text clustering with Levenshtein distances
edit
I think I totally misunderstood your question... try this
df=data.frame("Model"=c("Apple-1","New Apple","Organe","Orange2019","Cat"),
"Price"=c(10,11,13,15,19),stringsAsFactors = FALSE)
tags=data.frame("Model"=c("Apple-1","New Apple","Orange","Cat"),
"Tag"=c("A","A","B","B"),stringsAsFactors = FALSE)
df%>%rowwise()%>%mutate(Tag=if_else(!is.na(tags$Tag[which(!is.na(str_extract(Model,tags$Model)))[1]]),
tags$Tag[which(!is.na(str_extract(Model,tags$Model)))[1]],false="None"))
Model Price Tag
<chr> <dbl> <chr>
1 Apple-1 10 A
2 New Apple 11 A
3 Organe 13 None
4 Orange2019 15 B
5 Cat 19 B
I actually changed Orange for Organe so that you see what happens if there is not match ( none is returned)
Let us consider for simplicity only Kripke structures with a single agent whose knowledge is described by the modal operator K. We know that in all the corresponding Kripke structures where K is interpreted by equivalence there holds for any formula A
a) the formula KA -> A (Knowledge Axiom) is valid ,
b) but the formulas A -> KA and ¬KA are not valid.
Utilize these facts to show that such a behaviour of the modal operator K cannot be encoded by any boolean function (ie. Truth values defined by a table).
Hint: Suppose the truth value of KA can be calculated from the truth value of A using a truth table for K (in the same way as ¬A is calculated form A). Consider all possible truth tables for K and show that none of them grants the properties a) and b) mentioned above.
I dont understand that hint... making truth table of K is like constructing truth table of negation symbol ¬ , which in my mind doesnt make sense I think it makes sense only to make negation of something and not just negation
Consider all possible truth tables for K:
| A | K₁A | K₂A | K₃A | K₄A |
—————————————————————————————
| 1 | 1 | 1 | 0 | 0 |
—————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
Show that none of them grants the properties a) and b) mentioned above.
Case 1
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 2
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, A->KA is a tautology.
Case 3
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 4
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, ¬KA is a tautology.
Can desired behaviour of K be encoded by many-valued matrix?
For alethic modal systems, the answer is the following:
3 values are insufficient,
4 values are sufficient for the so-called basic modal logic,
any finite number of values is insufficient for syntactically “full” and deductively “natural” modal system.
See, e. g., introductory parts in the article by Jean-Yves Beseau.
I hope these results are relevant for epistemic modal systems.
Everything is in the title, I got from a database many columns, paired two-by-two containing codes and labels for some variables, I want an easy way to create half as many factors, with, for each factor levels/codes matching to the original two variables.
Here is an exemple of original data for two factors
| customer_type | customer_type_name | customer_status | customer_status_name |
|----------------------|----------------------|----------------------|----------------------|
| 1 | A | 2 | Beta |
| 2 | B | 2 | Beta |
| 3 | C | 1 | Alpha |
| 2 | B | 3 | Gamma |
| 1 | A | 4 | Delta |
| 3 | C | 2 | Beta |
i.e. a simpler way (simpler to call in a function for lots of variables) to do from dataframe "accounts"
a<-accounts[,c("customertypecode","customertypecodename")]
a<-a[!duplicated(a),]
a<-a[order(a$customertypecode),]
accounts$customertypecode<-factor(accounts$customertypecode,labels=a$customertypecodename[!is.na(a$customertypecodename)])
I have a dataset that I'm trying to chunk up into "events" based on a condition. I want to create a consecutive group number (ID) which increases each time the condition is met.
Some kinds of records indicate that a new event has started, while other kinds of records represent no change / staying the course.
For example, in this dataset whenever 'Action' is "Left" or "Right", a new event has started and 'Id' should be incremented by 1:
| Id | Action |
|-----+---------|
| 1 | Left |
| 2 | Forward |
| 3 | Forward |
| 4 | Right |
| 5 | Forward |
| 6 | Left |
| ... | ... |
The resulting table I want would look like:
| Id | Action | GroupId |
|-----+---------+---------|
| 1 | Left | 1 |
| 2 | Forward | 1 |
| 3 | Forward | 1 |
| 4 | Right | 2 |
| 5 | Forward | 2 |
| 6 | Left | 3 |
| ... | ... | ... |
In something like python I might do this with a counter and a for loop (pseudo-ish code):
GroupID = 1
for row in data:
if Action == "Left" OR Action == "Right":
GroupID = GroupID + 1
else:
GroupID = GroupID
I feel like this should be a really simple one-liner, but my brain is broken right now and I'm having a hard time conceptualizing this.
GroupId = cumsum(Action %in% c("Left", "Right"))