Questions tagged [crosstab]

A cross tab, also known as a "pivot table", is a method of summarizing data in tabular form. Typically, these have a category column in the left hand side, and multiple summary columns to the right. Each different category will have its own row. Be sure to also include the relevant language tag (python, R, sql-server etc.) on your question.

Resources:

1549 questions
3
votes
1 answer

Crosstable similar to Stata in R

I am working with a UCLA sample data set > read <- read.table("http://www.ats.ucla.edu/stat/mult_pkg/faq/general/sample.csv", header=TRUE, sep=",", quote="\"") > head(read) female read write math hon femalexmath 1 0 57 52 41 …
rmuc8
  • 2,869
  • 7
  • 27
  • 36
3
votes
2 answers

Invalid count and sum in cross tab query using PostgreSQL

I am using PostgreSQL 9.3 version database. I have a situation where I want to count the number of products sales and sum the amount of product and also want to show the cities in a column where the product have sale. Example Setup create table…
MAK
  • 6,824
  • 25
  • 74
  • 131
3
votes
1 answer

SQL Server : Crosstab/Pivot Price List

I have spent 2 days trying to get this to work but am not getting anywhere close to resolving this. I have a brought the data together to make a PriceList view | Category | Product | QtyFrom | QtyTo | Price …
Jim
  • 35
  • 3
3
votes
1 answer

R: Non-onerous method of getting CrossTable (gmodels) results nicely formatted (html) into markdown document

the code below --- title: "Example" output: html_document --- ```{r} require(datasets) data(esoph) require(knitr, quietly = TRUE, warn.conflicts = FALSE) kable(table(esoph$agegp, esoph$alcgp), caption = "Some sample") ``` Generates this pleasant…
Konrad
  • 17,740
  • 16
  • 106
  • 167
3
votes
1 answer

How do I combine two columns into single column in dynamic pivot

I have a schema like this demo(id, val, month, year, decide) Demo data and schema is given in this fiddle http://sqlfiddle.com/#!3/dd89d5/1 In output i want to transform the rows to columns. In the output i want, ID (11 14) (12 14) (2 15) ... …
3
votes
1 answer

Multiple Variables On One Side Of A Crosstab In R

I have a data set that looks like this: ID wts S2 S5.1 S5.2 S5.3 42 0.78 Male Yes No Yes 45 1.22 Female No Yes No 48 0.98 Male Yes Yes Yes 49 1.11 Female Yes Yes No 51 1.21 …
Eric W
  • 31
  • 3
3
votes
2 answers

Selecting table of properties as columns

I have two tables, things and properties: CREATE TABLE things ( id SERIAL PRIMARY KEY ); CREATE TABLE properties ( thing_id INT, key TEXT, value TEXT ); I want to select from things and join rows from properties as columns. For example,…
user2058002
3
votes
2 answers

Crosstab splitting results due to presence of unrelated field

I'm using postgres 9.1 with tablefunc:crosstab I have a table with the following structure: CREATE TABLE marketdata.instrument_data ( dt date NOT NULL, instrument text NOT NULL, field text NOT NULL, value numeric, CONSTRAINT…
Jim
  • 1,040
  • 1
  • 10
  • 16
3
votes
2 answers

Add a row with the sum of each colum in a table in R

I'm creating a cross table of 2 factors that has inside the sum of another variable b<-xtabs(utib~qpl+i , data=data ) This give me a table like <=2.5 2.5-5 5-10 10-50 50-150 150-250 >250 NA aaaa 3231 …
dax90
  • 1,088
  • 14
  • 29
3
votes
1 answer

Linq: How to transform rows to columns with a count (Crosstab data)?

I think I need a way to perform a pivot or crosstab using C# and Linq with an indeterminate number of columns. However, I will add some beginning detail to see where it goes. < Beginning detail > Imagine a table that has two fields: string…
Zachary Scott
  • 20,968
  • 35
  • 123
  • 205
3
votes
5 answers

How can I count the frequency of an answer in R?

I have an db that look like this: ID Group Drink 1 A yes 2 A no 3 A NA 4 B no 5 B no 6 B yes and I would like measure how many people of group A drinks and how many people in group B drinks. I am using…
Tormod
  • 83
  • 6
3
votes
3 answers

How do I create a Crosstab table with php mysql

I have the following recordset: Date |Role |Name ============================= 01/02/14 |Musician |Bob 01/02/14 |Leader |Jerry 01/02/14 |Singer |Carol 08/02/14 |Musician |Charles 08/02/14 |Leader |Baz 08/02/14 |Singer …
Jeremy Walmsley
  • 177
  • 3
  • 13
3
votes
2 answers

Using the crosstab() function while appending to the column names & using boolean logic

I'm using Postgresl 9.2 I need a crosstab table created from this: select id, imp from sg_imp_id (There are A LOT more rows than this) id | imp | -------+-------+ 1 | 111 | 2 | 111 | 2 | 121 | 2 | 122 | 3 | …
precose
  • 614
  • 1
  • 13
  • 36
3
votes
1 answer

I need to create a CrossTab Query in my VB.net program that will produce this table

I currently have a query in MS Access named Quarterly_Growth_Rates which produces the table below: Ticker Year Qtr Qtr_Growth AAPL 2013 3 21.46 AMZN 2013 3 12.59 BBBY 2013 3 4.11 GOOG 2013 3 0.04 V …
gromit1
  • 577
  • 2
  • 14
  • 36
3
votes
1 answer

How to use crosstab/pivot with multi dimensions

I tried using pivot tables to have more than one values in the 'values' field for the pivot_table function but it doesnt work, so im trying to see if i can do it with crosstabs. Here is my code table=pandas.pivot_table(xl2, values='Applications',…
jxn
  • 7,685
  • 28
  • 90
  • 172