creating a data fame with only matching numbers - frame

can you please help me with writing this code in R?
For example, if I have a dataset with 3 rows with several numbers as below,
"1 2 3 4 5"
"2 1 3 8 7"
"3 1 2 4 5"
From that, I want to crate a new data set keeping only the numbers that match with other raw numbers only , it would appear as something like below
"1 2 3"
"2 1 3"
"3 1 2"
How can I do that? I was thinking to use "AND" function in a "if" loop, but I don't know how to make r go through each different column to get the matching numbers that will match each raw number of all the data set, please let me know any ideas, Thanks

Related

SQL Server get random rows depending on the column's sum

For example, I have this table in my SQL Server database :
Document
NumberPageMax
First
48
Second
12
Third
4
Fourth
8
Fifth
1
Sixth
3
I need to get a random list of Document for whose the sum of NumberPageMax is equals to 50. If it's not possible to have exactly 50, it's ok to have a little more (first and sixth document for example to have 51).
Do you know if it's possible to do that in SQL and how ?
Thank you !

VBA - representing hierarchical data in Excel

I am fairly new to VBA in Excel and was hoping for some guidance on this problem. I am given hierarchical data from a database to perform a report, and the user would like to format the information such that an entry's children lie directly below it (a parent can have multiple children, child has only one parent). This could perhaps be done by indenting the Notes tab of the data by a few spaces. I was wondering how to first perform the reordering of the data by hierarchy, and then visually showing an indentation by adding, say, 5 spaces to the beginning of the Notes tab.
For sample data:
ID Parent ID Notes
0 NULL This is number 0.
1 0 This is number 1.
2 0 This is number 2.
3 1 This is number 3.
4 3 This is number 4.
5 0 This is number 5.
I would then like the data to be presented as such:
ID Parent ID Notes
0 NULL This is number 0.
1 0 -----This is number 1.
3 0 -----This is number 3.
4 1 ----------This is number 4.
2 3 -----This is number 2.
5 0 -----This is number 5.
Thank you so much! Your help is greatly appreciated :)

Business Objects CountIf by cell reference

So I have a column with this data
1
1
1
2
3
4
5
5
5
how can I do a count if where the value at any given location in the above table is equal to a cell i select? i.e. doing Count([NUMBER]) Where([NUMBER] = Coordinates(0,0)) would return 3, because there are 3 rows where the value is one in the 0 position.
it's basically like in excel where you can do COUNTIF(A:A, 1) and it would give you the total number of rows where the value in A:A is 1. is this possible to do in business objects web intelligence?
Functions in WebI operate on rows, so you have to think about it a little differently.
If your intent is to create a cell outside of the report block and display the count of specific values, you can use Count() with Where():
=Count([NUMBER];All) Where ([NUMBER] = "1")
In a freestanding cell, the above will produce a value of "3" for your sample data.
If you want to put the result in the same block and have it count up the occurrences of values on that row, for example:
NUMBER NUMBER Total
1 3
1 3
1 3
2 1
3 1
4 1
5 3
5 3
5 3
it gets a little more complicated. You have to have at least one other dimension in the query to reference. It can be anything, but you have to be counting something in conjunction with the NUMBER dimension. So, the following would work, assuming there's another dimension in the query named [Duh]:
=Count([NUMBER];All) ForAll([Duh])

Sql query or Microsoft-access query design to present data in the following manner

I am trying to design a query in Microsoft-access which should present the data in the following manner:
Car Make Black White Red
Total 2-door 4-door Total 2-door 4-door Total 2-door 4-door
---------------------------------------------------------------------------------------------------
Honda 4 2 2 3 1 2 4 3 1
Toyota 3 1 2 5 3 2 6 1 5
Ford 2 0 2 0 0 0 1 0 1
In Ms-Access query designer, I cant add more than one field which has a different criteria (for.eg white vs black). If I try to, it gives me nothing in the datasheet view (as if it tried to find a common car which is both white and black). Please tell me a sql query that I can use instead.
EDIT 1
Car Table:
-CarMake "Short text"
-Color "Short text"
-Door "Short text" (2-door or 4-door)
EDIT 2
This is what I was talking about. How to add more fields in here with different criteria for.eg white:
Two suggestions -
First, you could concatenate color & style into one variable and use that in the crosstab query - but you won't get the subtotals for colors.
Second, you could use iif statements in each column to define exactly what you want. Column 1 would be sum(iif(color="black",value,0)). Column 2 would be sum(iif(color="black" and model="2-door",value,0)). And so on. Not as simple as the 1st option, but you'll get exactly the columns you need.
SELECT Car.CarMake, Sum(IIf([color]="black",1,0)) AS BlackTotal, Sum(IIf([color]="black" And [door]="2-door",1,0)) AS Black_2D
FROM Car
GROUP BY Car.CarMake;

How to facet multiple columns in Google Refine

I have a data set with 30 columns and multiple rows (some cells have no data). I would like to be able to facet the columns in groups.
1 2 3 4...
Row1 A B C D
Row2 E A D F
Row3 Q A B H
Given the above data I would like the facet to retun the number of instances in a group of columns. For the first three columns I need the facet to return:
A - 3
B - 2
C - 1
D - 1
E - 1
Q - 1
I have tried to combine columns when I loaded the data but the individual data was grouped as well. This is not the desired outcome. For example:
ABC - 1
EAD - 1
QAB - 1
Thanks in advance.
I can't think of a more efficient way to do this off the top of my head, but you can do a custom facet with something like:
[ cells.["1"].value, cells.["2"].value, cells.["3"].value ]
where "1", "2", and "3" are the names of your columns. If your column names are single words, like "V1", "V2", "V3", and so on, you can also change the custom facet to something like:
[ cells.V1.value, cells.V2.value, cells.V3.value ]
With a lot of columns, this solution might be somewhat tedious though...
Did you tried to transpose all your column in one and facet on this 'master column'?
When transposing add the column name so you know from where the data comes from. The you can split your master column into 'source column' and 'data'.
You can find here the JSON code to transpose a large amount of column: http://googlerefine.blogspot.ca/2011/09/json-code-to-transpose-important-number.html
it should work for your project with a limited amount of edits.
Hope it help!