I have a data1.csv file with 74 rows containing names and about 300 columns containing dates.
I used the following codes:
data1<-read.csv(data1.csv)
names(data1)[1]<-paste("name")
So, the data looks like the following:
name v2 v3 etc v300
2011/08/01 2011/08/02 etc 2014/03/03
name1 123 132 etc 134
name2 12 14 etc 15
etc
For each name (name1 to name 74), data is for each date. I don't need V2-V300 - just want to name the second row as "date". How can I transpose data by each name such that the data looks like the following:
name date data
name1 2011/08/01 123
name1 2011/08/02 132
etc etc etc
name2 2011/08/01 12
name2 2011/08/02 14
etc etc etc
Thanks in advance,
chw
Related
For example, let us consider this table:
In this image consists of rows of 8 where names like Mike,Glenn,Daryl,Shane and Patricia is included with their respective ages
Id
Name
Age
1
Mike
25
2
Glenn
19
3
Glenn
19
4
Daryl
56
5
Shane
30
6
Shane
30
7
Patricia
16
Now I want to insert the type of query that will show the names without repetitions like This, not like This
EDIT: I entered the data from first picture. The request is to list the names without duplicates, as shown in the second and third picture but I will not convert them to text.
DISTINCT specifies removal of duplicate rows from the result set.
SELECT DISTINCT Name
FROM tablename
see: use DISTINCT in SELECT
You can use GROUP BY to achieve it.
SELECT * FROM your_table
GROUP BY your_table.name
ORDER BY id
With the data you gave, the result from this query will be:
id
name
age
1
Mike
25
2
Glenn
19
4
Deryl
56
5
Shane
30
7
Patricia
16
I have parsing Queries with below references
link1 - SET and Select Query combine Run in a Single MySql Query to pass result in pentaho
link2
Input will be shown in below Col1 showing ,In #input in the above reference link i am considering only 1 records and applying parsing logic for each cell , but issue is with multiple rows (n rows) and combining result with parsing logic.
Col1
--------------
22:4,33:4
33:6,89:7,69:2,63:2
78:6
blank record
22:6,63:1
I want to create single Query for same as in reference link i asked for.
Expected Output
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6
I tried solutions Passing values with this conditions
where condition pass 1 by 1 col1 in (my query)
MAX (col1)
group_concat
but i am not getting expected output to fit this all things in a single query.
I finally found solution for my question. and group_concat worked for this
#input= (select group_concat(Col1) from (select Col1 from table limit 10)s);
group_concat will merge all the rows of Col1 into comma seperated string
22:4,33:4,33:6,89:7,69:2,63:2,78:6,blank record,22:6,63:1
as we have now single string we can apply same logic as shown in link 1
we can replace blank record with REPLACE command and neglect it.
Output after using logic from link1 result
xyz count
------------
22 4
33 4
33 6
89 7
69 2
63 2
78 6
22 6
63 1
Just use Group by
select xyz,sum(count) from (select link1 output)s group by xyz;
will give you Final Output
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6
I have an answer spreadsheet linked to a Google form. I wish to get the last date that and answer was submitted.
Lets say I my entries look like this :
DATA :
A B
1 Date String
2 2015-05-09 Abb
3 2015-05-11 Bcc
4 2015-05-12 Cdd
5 2015-05-20 Bcc
6 2015-06-01 Abb
The result that i want would look like this :
A B
1 String Last date
2 Abb 2015-06-01
3 Bcc 2015-05-20
4 Cdd 2015-05-12
Ideally, I would like to do so with formulas only!
Assuming your data starts in row 2, try:
=ArrayFormula(iferror(vlookup(unique(B2:B), sort({B2:B, A2:A}, 2, 0), {1, 2}, 0 )))
Change ranges to suit. Don't forget to include the sheetname if you need that formula to appear on another sheet.
How to convert a empty string into a string
ie i have a column with names and in that column there are empty strings I want those empty strings to be removed and renamed as UNKNOWN.
Before :
ID Name Age
1 15
2 Sam 20
3 47
4 Smith 25
After :
ID Name Age
1 UNKNOWN 15
2 Sam 20
3 UNKNOWN 47
4 Smith 25
You can use an "if-else" expression in the derived column transform dialog. For example, you could try:
[Name] == ''?'UNKNOWN':[Name]
More info is here: http://msdn.microsoft.com/en-us/library/ms141069.aspx
Let's say I have a Text document. There are two columns. Column 1 contains a list of names while column contains a list of value relating to those names. The problem is column 1 may have same names repeating on different rows. This is not an error though.
For ex:
Frank Burton 13
Joe Donnigan 22
John Smith 45
Cooper White 53
Joe Donnigan 19
What are the ways to organize my data in a way that I would have column 1 with unique data names and column 2 with the values summed together relating column 1? What can I do if I have these data in excel?
For ex:
Frank Burton 13
Joe Donnigan 41
John Smith 45
Cooper White 53
Thanks a bunch!
In mySQL you could write a query similar to...
Select col1, Sum(col2) FROM TableName group by col1
In Excel you could use a pivot table to group the information together
Insert Pivot table, select range enter values as in image below.