Home About Contact
Ivory Research Interface Data Analysis Services, Intro to R and Cross Tabulation.

Ivory Research Interface Data Analysis Services.

Projects.

R Tutorial: Introduction to R and Cross Tabulation.

Learning Objectives.

From this case study you should learn how to:

Introduction.

Part of the entrepreneurial activity of thinking is to be able to categorize and find patterns in and between categories. A method of doing this is to take surveys and analyze the responses from survey subjects. In this module you will be given market survey data. The survey data is of 421 respondent answers to questions regarding Ready-to-Wear (RTW) apparel. Background on the data as to the purpose and objectives of the survey are in the case study titled, "Urbanist Laboratory: Design, Printing, Marketing." This case study looks at the market and competitors competing in the RTW Apparel industry that targets college students primarily within the University Belt of Manila. Make sure you take note of how members of the market receive classification, and how each category corresponds to a set of demographic and behavioral traits. After reading the case study, download the survey and begin looking at classifications and associations between classes of the target market using R Statistics. Do not worry, just follow the instructions on how to get R to access and analyze the data.

The Urbanist Laboratory Case Study download is at the following link: Urbanist Laboratory Case Study

A CSV file for the Urbanist Laboratory case study download is at the following link: UL Survey Raw Data

Place these in a directory within your computer. This is essential as you will need the path to this folder in order to execute the commands further on in this module.

Installing R Statistics.

Download the version of R appropriate for your operating system from: https://cran.r-project.org/

When you download R, just follow the installation prompts.

Now, you will need to download several packages to run the analyses we are looking to do. As such, when you have successfully downloaded R into your laptop or computer you will need to begin programming in the environment. You will need to install the package titled gmodels. The package gmodels allows you to run crosstabluations of data to identify traits in the market that are of interest, such as the number of men or women who are willing to pay a specific price for a product, or the number of people of a particular economic class willing to pay a particular price for a good or service. When you download packages from the CRAN Repository, make sure your CRAN mirror is for the Philippines.

Importing and Analyzing Data in an R Session.

Before you begin coding in R, it is advisable to use a simple UTF-8 text (TXT) file, whose font is set to Courier. R will only recognize commands in the Courier font. Also, it will be easier to program from a TXT file, such as one from Notepad (in Windows), or TextEdit (in Mac), as you can quickly go back and forth from the commmand screen to adjust your codes. Figure 1, describes a possible screen arrangement.


Figure 1. Simple Terminal and Text Editor Screen Layout.


When you have set your CRAN mirror to the proper domestic server, you will have to now install a package.

  1. Set your reference drive. You do this for every R session, such that the program knows where to find the data it will analyze and write information to. The command to set your reference drive is setwd. The command code follows a particular protocol. The protocol is:

  2. setwd("/Directory/Subdirectory")

    Note, that the specific file name is not stated, you are only telling the program what specific directory to look at. As such, my code to set the reference directory is:


    setwd("/Users/username/Desktop")

  1. Install the packages using the install.packages command. Like the setwd command, the install.packages command has a particular syntax. The syntax is:

  2. install.packages(Name_of_Package)

    To install the package gmodels, the code is:


    install.packages(gmodels, dependencies=TRUE)


    At this point the program will go to the domestic CRAN mirror and download the package and its dependencies into your system. The packages are not active in the session yet. Take notice of the argument dependencies=TRUE, this will automatically download all other supporting packages necessary to run the invoked package. Just follow any instructions given to you during this process. It is pretty straight forward.


  1. Activate the packages you will use for the R session. To activate an already installed package in R, you will need to use the command library. The library command will go into your local system library of packages, and activate the package you tell it to for the session. To activate the gmodels package, the syntax is:

  2. library(gmodels)

  1. Establish a vector of data. We can think of an R vector as a vessel (an object) that holds a set of data in the session. In R, you must establish vectors from which the program will analyze. This is relatively straightforward to do. The syntax follows this logic:

  2. Name_of_Vector <- Command(File_Name)

    Note how there are no spaces in the vector name or the file name. Similar to C++ or even Maya, R recognizes spaces as the end of an object designation or command.

    Since we are using the base functions in R to read a CSV file, the command to bring data into the session is read.csv. This command will tell the program to look at the filename you provide and create what is effectively a TXT version of the data. The code syntax to do this is:


    Name_of_the_Vector <- read.csv("FILENAME.csv", header=TRUE)


    For the Urbanist Laboratory case study let us use the code:


    UL.CT <- read.csv("UL_Survey_Raw_Data.csv", header=TRUE)


    What R will do is create a vector by the name of UL.CT from the CSV file "UL_Survey_Raw_Data.csv", by which to reference future analyses you command it to.


  1. Look at your data in R. To see what R sees of your spreadsheet the idea is to make the program print the data. The code to print data is based in the print command. Hence, the code syntax is:

  2. print(Name of Vector)

    This will make R print what it sees of the vector that you tell it to look at. For the Urbanist Laboratory case, the code is:


    print(UL.CT)

    The command print will allow us to see all information brought into the session. To view the first six (6) lines of a data set, use the command head. In order to see the last six (6) lines of a data set, use the tail command.


    head(UL.CT)

    The output should look something like the following first six lines for each response field:


                  Response.ID  Time.Started Date.Submitted   Status     Country        City
                1           4 4/17/13 10:54  4/17/13 10:59 Complete Philippines    San Juan
                2           5 4/17/13 11:42  4/17/13 11:45 Complete Philippines      Manila
                3           7 4/17/13 12:45  4/17/13 12:50 Complete Philippines Ugong Norte
                4           9 4/17/13 14:18  4/17/13 14:23 Complete      Canada      Surrey
                5          11 4/17/13 20:35  4/17/13 20:42 Complete Philippines      Makati
                6          16  4/18/13 2:28   4/18/13 2:35 Complete Philippines     Marilao
                  Region Postal My.gender.is.    I.consider.myself.
                1      9     NA          Male Upper-Middle Class: B
                2     D9     NA          Male Lower-Middle Class: C
                3     F2     NA          Male Lower-Middle Class: C
                4     BC     NA        Female Upper-Middle Class: B
                5     D9     NA          Male Lower-Middle Class: C
                6     13     NA          Male Lower-Middle Class: C
                  My.educational.background.is. My.career.state.is.
                1        Student: Undergraduate         Team Leader
                2        Student: Undergraduate         Entry Level
                3   Graduate: Bachelor's Degree          Apprentice
                4   Graduate: Bachelor's Degree          Unemployed
                5        Student: Undergraduate  Owner: Independent
                6        Student: Undergraduate          Unemployed
                  Please.state.the.university..and.major.you.studied.at...Note..For.example..if.you.studied.Architecture.at.the.University.of.Santo.Tomas..please.state..UST..Architecture..or.University.of.Santo.Tomas..Architecture..
                1                                                                                                                                                          De La Salle Araneta University, Doctor of Veterinary Medicine
                2                                                                                                                                                                                                                PUP; IT
                3                                                                                                                                                                                                      UST, Architecture
                4                                                                                                                                                                                                                    UST
                5                                                                                                                                                                                                           PMI,Nautical
                6                                                                                                                                                                Benguet State University, Doctor of Veterinary Medicine
                  Please.rate.the.importance.of.Style.Color.in.your.reasons.for.purchasing.clothing.
                1                                                                                  7
                2                            1 (Least important reason for me to purchase clothing.)
                3                                                                                  7
                4                                                                                  7
                5                                                                                  6
                6                             9 (Most important reason for me to purchase clothing.)
                  Please.rate.the.importance.of.Price.in.your.reasons.for.purchasing.clothing.
                1                                                                            8
                2                       9 (Most important reason for me to purchase clothing.)
                3                                                                            7
                4                                                                            8
                5                                                                            6
                6                       9 (Most important reason for me to purchase clothing.)
                  Please.rate.the.importance.of.Comfort.in.your.reasons.for.purchasing.clothing.
                1                                                                              5
                2                         9 (Most important reason for me to purchase clothing.)
                3                                                                              8
                4                         9 (Most important reason for me to purchase clothing.)
                5                                                                              7
                6                         9 (Most important reason for me to purchase clothing.)
                  Please.rate.the.importance.of.Durability.in.your.reasons.for.purchasing.clothing.
                1                                                                                 5
                2                                                                                 7
                3                                                                                 8
                4                                                                                 8
                5                            9 (Most important reason for me to purchase clothing.)
                6                            9 (Most important reason for me to purchase clothing.)
                  Please.rate.the.importance.of.Brand.Reputation.in.your.reasons.for.purchasing.clothing.
                1                                                                                       7
                2                                                                                       6
                3                                                                                       6
                4                                                                                       7
                5                                                                                       8
                6                                 1 (Least important reason for me to purchase clothing.)
                  Please.rate.the.importance.of.Fit.in.your.reasons.for.purchasing.clothing.
                1                     9 (Most important reason for me to purchase clothing.)
                2                                                                          7
                3                                                                          8
                4                                                                          8
                5                                                                          8
                6                     9 (Most important reason for me to purchase clothing.)
                  What.4.colors.would.you.most.like.to.see.for.your.college.apparel...For.example..if.you.like.yellow..red..blue..and.white..state..Yellow..Red..Blue..White..or.White..Blue..Yellow..Red..
                1                                                                                                                                                                        Black, White, Grey
                2                                                                                                                                                                        black, white, blue
                3                                                                                                                                                               White, Maroon, Brown, Black
                4                                                                                                                                                                   Black, Blue, Red, Brown
                5                                                                                                                                                                   Black,Violet,Yellow,Red
                6                                                                                                                                                                      red,blue,white,black
                  How.much.would.you.pay.for.a.T.shirt.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                1                                                                                                                         Php 250.00
                2                                                                                                                                350
                3                                                                                                                Php 150.00 - 250.00
                4                                                                                                                                250
                5                                                                                                                         Php.300.00
                6                                                                                                                          Php150.00
                  How.much.would.you.pay.for.a.Jacket.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                1                                                                                                                        Php 750.00
                2                                                                                                                               800
                3                                                                                                                    Php 600-900.00
                4                                                                                                                               500
                5                                                                                                                        Php.500.00
                6                                                                                                                         Php250.00
                  How.much.would.you.pay.for.a.Baseball.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                1                                                                                                                              Php 350.00
                2                                                                                                                                     250
                3                                                                                                                              Php 200.00
                4                                                                                                                                     150
                5                                                                                                                              Php.300.00
                6                                                                                                                                 Php00.0
                  How.much.would.you.pay.for.a.Hooded.Sweater.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                1                                                                                                                               Php 1000.00
                2                                                                                                                                       800
                3                                                                                                                               Php 600-900
                4                                                                                                                                       350
                5                                                                                                                                Php.400.00
                6                                                                                                                                   Php00.0
                  How.much.would.you.pay.for.an.Athletic.Sweater..non.hooded..from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                1                                                                                                                                              Php 1,000.00
                2                                                                                                                                                       800
                3                                                                                                                                            Php 600-900.00
                4                                                                                                                                                       400
                5                                                                                                                                                Php.500.00
                6                                                                                                                                                   Php00.0
                  How.much.would.you.pay.for.a.Knitted.Head.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                1                                                                                                                                  Php 250.00
                2                                                                                                                                         250
                3                                                                                                                                  Php 200.00
                4                                                                                                                                         200
                5                                                                                                                                  Php.100.00
                6                                                                                                                                     Php00.0
                                                         What.is.your.definition.of.comfortable.clothing.
                1                                                                                   Firm.
                2                                                      loose-fitting and breathable shirt
                3 When you can actually wear it on different occasion and on different times and seasons.
                4                                                            Something that fits me right
                5                                                                            easy to wear
                6                        clothing that do not stick to the body or skin when im sweating.


    The following are the last six lines of each response field using the command tail. Pay attention to the left most numbers, these are the rownames. In this case the row names indicate the number of rows in the vector.

    tail(UL.CT)
                        Response.ID  Time.Started Date.Submitted   Status     Country        City
                    416          38  4/25/13 6:50   4/25/13 6:55 Complete Philippines  Valenzuela
                    417          40  4/25/13 9:59  4/25/13 10:04 Complete Philippines Quezon City
                    418          41  4/26/13 6:34   4/26/13 6:37 Complete Philippines      Makati
                    419          42 4/26/13 11:35  4/26/13 11:38 Complete Philippines  Cabanatuan
                    420          43 4/26/13 18:21  4/26/13 18:24 Complete Philippines      Makati
                    421          44 4/26/13 19:09  4/26/13 19:14 Complete Philippines Quezon City
                        Region Postal My.gender.is.    I.consider.myself.
                    416     53     NA        Female Lower-Middle Class: C
                    417     F2     NA        Female Upper-Middle Class: B
                    418     D9     NA          Male Lower-Middle Class: C
                    419     A9     NA          Male Lower-Middle Class: C
                    420     D9     NA        Female Upper-Middle Class: B
                    421     F2     NA          Male Upper-Middle Class: B
                        My.educational.background.is. My.career.state.is.
                    416        Student: Undergraduate         Team Leader
                    417        Student: Undergraduate          Unemployed
                    418        Student: Undergraduate          Unemployed
                    419   Graduate: Bachelor's Degree         Entry Level
                    420   Graduate: Bachelor's Degree          Unemployed
                    421   Graduate: Bachelor's Degree         Entry Level
                        Please.state.the.university..and.major.you.studied.at...Note..For.example..if.you.studied.Architecture.at.the.University.of.Santo.Tomas..please.state..UST..Architecture..or.University.of.Santo.Tomas..Architecture..
                    416                                                                                                                                                                               University of Santo Tomas, AB Philosophy
                    417                                                                                                                                                                                                           DLSU Biology
                    418                                                                                                                                                                                                UST AB Legal Management
                    419                                                                                                                                                                                           UST, ELectronics Engineering
                    420                                                                                                                                                                                                           UST, Biology
                    421                                                                                                                                                                                              UST, Marketing Management
                        Please.rate.the.importance.of.Style.Color.in.your.reasons.for.purchasing.clothing.
                    416                             9 (Most important reason for me to purchase clothing.)
                    417                             9 (Most important reason for me to purchase clothing.)
                    418                             9 (Most important reason for me to purchase clothing.)
                    419                             9 (Most important reason for me to purchase clothing.)
                    420                                                                                  8
                    421                                                                                  8
                        Please.rate.the.importance.of.Price.in.your.reasons.for.purchasing.clothing.
                    416                       9 (Most important reason for me to purchase clothing.)
                    417                       9 (Most important reason for me to purchase clothing.)
                    418                                                                            5
                    419                                                                            4
                    420                       9 (Most important reason for me to purchase clothing.)
                    421                                                                            5
                        Please.rate.the.importance.of.Comfort.in.your.reasons.for.purchasing.clothing.
                    416                         9 (Most important reason for me to purchase clothing.)
                    417                                                                              8
                    418                         9 (Most important reason for me to purchase clothing.)
                    419                                                                              8
                    420                                                                              8
                    421                         9 (Most important reason for me to purchase clothing.)
                        Please.rate.the.importance.of.Durability.in.your.reasons.for.purchasing.clothing.
                    416                            9 (Most important reason for me to purchase clothing.)
                    417                                                                                 8
                    418                            9 (Most important reason for me to purchase clothing.)
                    419                                                                                 7
                    420                                                                                 7
                    421                            9 (Most important reason for me to purchase clothing.)
                        Please.rate.the.importance.of.Brand.Reputation.in.your.reasons.for.purchasing.clothing.
                    416                                 1 (Least important reason for me to purchase clothing.)
                    417                                                                                       7
                    418                                 1 (Least important reason for me to purchase clothing.)
                    419                                  9 (Most important reason for me to purchase clothing.)
                    420                                                                                       5
                    421                                                                                       8
                        Please.rate.the.importance.of.Fit.in.your.reasons.for.purchasing.clothing.
                    416                                                                          7
                    417                     9 (Most important reason for me to purchase clothing.)
                    418                                                                          5
                    419                     9 (Most important reason for me to purchase clothing.)
                    420                                                                          8
                    421                     9 (Most important reason for me to purchase clothing.)
                        What.4.colors.would.you.most.like.to.see.for.your.college.apparel...For.example..if.you.like.yellow..red..blue..and.white..state..Yellow..Red..Blue..White..or.White..Blue..Yellow..Red..
                    416                                                                                                                                                                    Blue, Black, Red, Gray
                    417                                                                                                                                                                  white green yellow black
                    418                                                                                                                                                                 Blue, Yellow, White, Gray
                    419                                                                                                                                                                white, black, yellow, grey
                    420                                                                                                                                                                              White, Black
                    421                                                                                                                                                                Yellow, Black, White, Blue
                        How.much.would.you.pay.for.a.T.shirt.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                    416                                                                                                                            150 Php
                    417                                                                                                                                150
                    418                                                                                                                                200
                    419                                                                                                                                200
                    420                                                                                                                                150
                    421                                                                                                                         Php 250.00
                        How.much.would.you.pay.for.a.Jacket.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                    416                                                                                                                           350 Php
                    417                                                                                                                               250
                    418                                                                                                                             1,000
                    419                                                                                                                              1000
                    420                                                                                                                               600
                    421                                                                                                                      Php 1,000.00
                        How.much.would.you.pay.for.a.Baseball.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                    416                                                                                                                                   0 php
                    417                                                                                                                                     150
                    418                                                                                                                                     250
                    419                                                                                                                                     100
                    420                                                                                                                                     100
                    421                                                                                                                              Php 200.00
                        How.much.would.you.pay.for.a.Hooded.Sweater.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                    416                                                                                                                                   400 Php
                    417                                                                                                                                       300
                    418                                                                                                                                     1,000
                    419                                                                                                                                      1000
                    420                                                                                                                                       700
                    421                                                                                                                                Php 500.00
                        How.much.would.you.pay.for.an.Athletic.Sweater..non.hooded..from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                    416                                                                                                                                                   300 Php
                    417                                                                                                                                                       300
                    418                                                                                                                                                     1,000
                    419                                                                                                                                                      1000
                    420                                                                                                                                                       650
                    421                                                                                                                                                Php 300.00
                        How.much.would.you.pay.for.a.Knitted.Head.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php..
                    416                                                                                                                                     175 Php
                    417                                                                                                                                         150
                    418                                                                                                                                         400
                    419                                                                                                                                         100
                    420                                                                                                                                         100
                    421                                                                                                                                  Php 300.00
                                                                                                                   What.is.your.definition.of.comfortable.clothing.
                    416                                               Comfortable clothing is being able act freely without any hesitations on what one is wearing.
                    417                                                                                                                                easy to wear
                    418  I consider my clothes comfortable if they allow me to move freely without minding the hassle of the clothing being destroyed or whatsoever
                    419                                                                                                                           style and comfort
                    420                                                               It is something made out of pure cotton, fits me well and reflects back heat.
                    421 For me, comfortable clothing is being able to have a perfect match with the clothes one wears - in terms of the color, size/fit and others.


    The program will proceed to display the data it sees in the reference file. Once the data is shown in the field, you may copy this data and paste it into an Excel spreadsheet.


  1. To see various column names in the vector, use the command colnames(x) to retrieve a list of the column names. The command receives a vector name, x in parentheses. In the following line, Vector_Name is the x argument.

  2. colnames(Vector_Name)

    In this case we want to look at the column names of the object named UL.CT. Hence, the command line becomes:


    colnames(UL.CT)

    The following 27 lines are the names of each column in the UL.CT vector.

                    [1] "Response.ID"                                                                                                                                                                                                           
                    [2] "Time.Started"                                                                                                                                                                                                          
                    [3] "Date.Submitted"                                                                                                                                                                                                        
                    [4] "Status"                                                                                                                                                                                                                
                    [5] "Country"                                                                                                                                                                                                               
                    [6] "City"                                                                                                                                                                                                                  
                    [7] "Region"                                                                                                                                                                                                                
                    [8] "Postal"                                                                                                                                                                                                                
                    [9] "My.gender.is."                                                                                                                                                                                                         
                   [10] "I.consider.myself."                                                                                                                                                                                                    
                   [11] "My.educational.background.is."                                                                                                                                                                                         
                   [12] "My.career.state.is."                                                                                                                                                                                                   
                   [13] "Please.state.the.university..and.major.you.studied.at...Note..For.example..if.you.studied.Architecture.at.the.University.of.Santo.Tomas..please.state..UST..Architecture..or.University.of.Santo.Tomas..Architecture.."
                   [14] "Please.rate.the.importance.of.Style.Color.in.your.reasons.for.purchasing.clothing."                                                                                                                                    
                   [15] "Please.rate.the.importance.of.Price.in.your.reasons.for.purchasing.clothing."                                                                                                                                          
                   [16] "Please.rate.the.importance.of.Comfort.in.your.reasons.for.purchasing.clothing."                                                                                                                                        
                   [17] "Please.rate.the.importance.of.Durability.in.your.reasons.for.purchasing.clothing."                                                                                                                                     
                   [18] "Please.rate.the.importance.of.Brand.Reputation.in.your.reasons.for.purchasing.clothing."                                                                                                                               
                   [19] "Please.rate.the.importance.of.Fit.in.your.reasons.for.purchasing.clothing."                                                                                                                                            
                   [20] "What.4.colors.would.you.most.like.to.see.for.your.college.apparel...For.example..if.you.like.yellow..red..blue..and.white..state..Yellow..Red..Blue..White..or.White..Blue..Yellow..Red.."                             
                   [21] "How.much.would.you.pay.for.a.T.shirt.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                                    
                   [22] "How.much.would.you.pay.for.a.Jacket.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                                     
                   [23] "How.much.would.you.pay.for.a.Baseball.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                               
                   [24] "How.much.would.you.pay.for.a.Hooded.Sweater.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                             
                   [25] "How.much.would.you.pay.for.an.Athletic.Sweater..non.hooded..from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                             
                   [26] "How.much.would.you.pay.for.a.Knitted.Head.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                           
                   [27] "What.is.your.definition.of.comfortable.clothing."
  1. To rename a column it is necessary to use the command colnames(x) again. In this particular use, it is necessary to indicate the name of the column you would like to change by using the square brackets [ ], which allow users to access particular elements of an object. Think of the square brackets as a way to access a particular subset of within a given data set.

    In the following line of code, colnames looks at the UL.CT vector, for any column name with a string "My.gender.is." and replaces that string with merely the character string Gender.

  2. colnames(UL.CT)[colnames(UL.CT) == "My.gender.is."] <- "Gender"

    An execution of the above line of code will have changed the ninth column name "My.gender.is." to just "Gender". Another run of the colnames command for the UL.CT vector, colnames(UL.CT), should produce a result similar to the following. Notice, that the ninth column name is changed.

                    [1] "Response.ID"                                                                                                                                                                                                           
                    [2] "Time.Started"                                                                                                                                                                                                          
                    [3] "Date.Submitted"                                                                                                                                                                                                        
                    [4] "Status"                                                                                                                                                                                                                
                    [5] "Country"                                                                                                                                                                                                               
                    [6] "City"                                                                                                                                                                                                                  
                    [7] "Region"                                                                                                                                                                                                                
                    [8] "Postal"                                                                                                                                                                                                                
                    [9] "Gender"                                                                                                                                                                                                                
                   [10] "I.consider.myself."                                                                                                                                                                                                    
                   [11] "My.educational.background.is."                                                                                                                                                                                         
                   [12] "My.career.state.is."                                                                                                                                                                                                   
                   [13] "Please.state.the.university..and.major.you.studied.at...Note..For.example..if.you.studied.Architecture.at.the.University.of.Santo.Tomas..please.state..UST..Architecture..or.University.of.Santo.Tomas..Architecture.."
                   [14] "Please.rate.the.importance.of.Style.Color.in.your.reasons.for.purchasing.clothing."                                                                                                                                    
                   [15] "Please.rate.the.importance.of.Price.in.your.reasons.for.purchasing.clothing."                                                                                                                                          
                   [16] "Please.rate.the.importance.of.Comfort.in.your.reasons.for.purchasing.clothing."                                                                                                                                        
                   [17] "Please.rate.the.importance.of.Durability.in.your.reasons.for.purchasing.clothing."                                                                                                                                     
                   [18] "Please.rate.the.importance.of.Brand.Reputation.in.your.reasons.for.purchasing.clothing."                                                                                                                               
                   [19] "Please.rate.the.importance.of.Fit.in.your.reasons.for.purchasing.clothing."                                                                                                                                            
                   [20] "What.4.colors.would.you.most.like.to.see.for.your.college.apparel...For.example..if.you.like.yellow..red..blue..and.white..state..Yellow..Red..Blue..White..or.White..Blue..Yellow..Red.."                             
                   [21] "How.much.would.you.pay.for.a.T.shirt.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                                    
                   [22] "How.much.would.you.pay.for.a.Jacket.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                                     
                   [23] "How.much.would.you.pay.for.a.Baseball.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                               
                   [24] "How.much.would.you.pay.for.a.Hooded.Sweater.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                             
                   [25] "How.much.would.you.pay.for.an.Athletic.Sweater..non.hooded..from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                             
                   [26] "How.much.would.you.pay.for.a.Knitted.Head.Cap.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."                                                                           
                   [27] "What.is.your.definition.of.comfortable.clothing."

    The same process is done on the 14th, 15th and 21st columns. The 14th column is renamed to Imprt.Style. The 15th column is renamed to Imprt.Price. The 21st column is renamed it to Price. Thus, the codes to rename the columns are:


    colnames(UL.CT)[colnames(UL.CT) == "Please.rate.the.importance.of.Style.Color.in.your.reasons.for.purchasing.clothing."] <- "Imprt.Style"

    Note: Code Line to Rename Column 14 to Imprt.Style.


    colnames(UL.CT)[colnames(UL.CT) == "Please.rate.the.importance.of.Price.in.your.reasons.for.purchasing.clothing."] <- "Imprt.Price"

    Note: Code Line to Rename Column 15 to Imprt.Price.


    colnames(UL.CT)[colnames(UL.CT) == "How.much.would.you.pay.for.a.T.shirt.from.your.university..or.college...Note..Please.state.your.response.in.Philippine.Peso..Php.."] <- "Price"

    Note: Code Line to Rename Column 21 to Price.


  1. Start analyzing. This now requires you to use different functions that trigger analysis tools already in the statistics environment and the active packages in the session.

Methods of Cross Tablulation: Single Trait, CrossTable.

For crosstablations, we could use the function CrossTable. This command is found in the package gmodels. Urbanist Laboratory surveyed 421 people to determine individual qualities such as gender, economic class affiliation, on to most important product qualities in purchasing. In this case, we want to know descriptive statistics regarding the prices that each gender was willing to pay for a T-Shirt. The function CrossTable takes two categories of data and generates descriptive statistics for all respondents that share the same paired categories, such as Females willing to pay Php200 for a T-Shirt. Since we have a vector to work from, the code to see the distribution of willingness-to-pay for each gender is:


CrossTable(UL.CT$Gender, UL.CT$Price, resid=TRUE, format="SPSS")


This line of code produces the following output:


   Cell Contents
            |-------------------------|
            |                   Count |
            | Chi-square contribution |
            |             Row Percent |
            |          Column Percent |
            |           Total Percent |
            |                Residual |
            |-------------------------|
            
            Total Observations in Table:  421 
            
                         | UL.CT$Price 
            UL.CT$Gender |                 100  |                1000  |                 150  |             150 Php  |             150 php  |             150,200  |             150,250  |             150,300  |             150-200  |             150-250  |            1500-300  |                 180  |                 195  |                 200  |             200,250  |             200-300  |             200-350  |             200-400  |                 220  |                 250  |             250,300  |             250-300  |             250-350  |             250-500  |              250php  |                 300  |          300 to 400  |             300-400  |             300-450  |          300.00 php  |                300P  |              300php  |                 350  |             350 Php  |             350-500  |              350Php  |                350p  |                 380  |                 400  |             400 Php  |              400php  |                 450  |              450php  |           5,001,000  |                  50  |                 500  |              500PHP  |              500php  |                 600  |                 650  |               99php  |               P 250  |           P1,500.00  |                P150  |                P180  |                P200  |             P200.00  |                P300  |        P300 to P500  |             P300.00  |             P350.00  |                P600  |             PHP 150  |             PHP 300  |              PhP500  |          Php 150.00  | Php 150.00 - 250.00  |             Php 200  |          Php 200.00  |             Php 250  |          Php 250.00  |             Php 300  |          Php 300.00  |             Php 450  |             Php 500  |          Php 900.00  |         Php. 200.00  |            Php. 250  |         Php. 300.00  |          Php.300.00  |          Php.350.00  |         Php1,000.00  |              Php150  |           Php150.00  |              Php200  |              Php250  |           Php250.00  |           Php299.95  |              Php300  |              Php350  |           Php350.00  |           Php400.00  |              Php500  |   less than 400 Php  |             php 250  |           Row Total | 
            -------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
                  Female |                  7  |                  0  |                 29  |                  1  |                  0  |                  1  |                  0  |                  0  |                  4  |                  2  |                  1  |                  1  |                  0  |                 41  |                  0  |                  1  |                  0  |                  0  |                  0  |                 40  |                  2  |                  0  |                  1  |                  0  |                  1  |                 28  |                  1  |                  1  |                  0  |                  1  |                  0  |                  1  |                 11  |                  1  |                  1  |                  0  |                  1  |                  0  |                 12  |                  0  |                  1  |                  2  |                  1  |                  1  |                  1  |                  8  |                  1  |                  1  |                  1  |                  1  |                  0  |                  1  |                  1  |                  2  |                  1  |                  3  |                  2  |                  2  |                  1  |                  4  |                  1  |                  0  |                  1  |                  1  |                  0  |                  1  |                  0  |                  5  |                  1  |                  4  |                  2  |                  1  |                  1  |                  1  |                  1  |                  0  |                  1  |                  0  |                  1  |                  0  |                  1  |                  0  |                  2  |                  0  |                  2  |                  1  |                  1  |                  0  |                  0  |                  0  |                  1  |                  0  |                  0  |                  1  |                  1  |                257  | 
                         |              0.110  |              1.221  |              0.630  |              0.249  |              0.610  |              0.249  |              0.610  |              0.610  |              0.294  |              0.497  |              0.249  |              0.249  |              0.610  |              1.358  |              0.610  |              0.040  |              0.610  |              0.610  |              0.610  |              0.002  |              0.080  |              0.610  |              0.249  |              0.610  |              0.249  |              0.315  |              0.249  |              0.040  |              0.610  |              0.249  |              0.610  |              0.249  |              0.440  |              0.377  |              0.249  |              0.610  |              0.249  |              0.610  |              0.093  |              0.610  |              0.249  |              0.016  |              0.249  |              0.249  |              0.249  |              1.116  |              0.249  |              0.249  |              0.249  |              0.249  |              0.610  |              0.249  |              0.249  |              0.016  |              0.249  |              0.746  |              0.497  |              0.016  |              0.249  |              0.994  |              0.040  |              0.610  |              0.249  |              0.249  |              0.610  |              0.249  |              0.610  |              1.243  |              0.040  |              0.994  |              0.363  |              0.377  |              0.040  |              0.249  |              0.040  |              0.610  |              0.249  |              1.221  |              0.249  |              0.610  |              0.249  |              0.610  |              0.497  |              0.610  |              0.016  |              0.249  |              0.040  |              0.610  |              1.221  |              0.610  |              0.249  |              0.610  |              0.610  |              0.249  |              0.249  |                     | 
                         |              2.724% |              0.000% |             11.284% |              0.389% |              0.000% |              0.389% |              0.000% |              0.000% |              1.556% |              0.778% |              0.389% |              0.389% |              0.000% |             15.953% |              0.000% |              0.389% |              0.000% |              0.000% |              0.000% |             15.564% |              0.778% |              0.000% |              0.389% |              0.000% |              0.389% |             10.895% |              0.389% |              0.389% |              0.000% |              0.389% |              0.000% |              0.389% |              4.280% |              0.389% |              0.389% |              0.000% |              0.389% |              0.000% |              4.669% |              0.000% |              0.389% |              0.778% |              0.389% |              0.389% |              0.389% |              3.113% |              0.389% |              0.389% |              0.389% |              0.389% |              0.000% |              0.389% |              0.389% |              0.778% |              0.389% |              1.167% |              0.778% |              0.778% |              0.389% |              1.556% |              0.389% |              0.000% |              0.389% |              0.389% |              0.000% |              0.389% |              0.000% |              1.946% |              0.389% |              1.556% |              0.778% |              0.389% |              0.389% |              0.389% |              0.389% |              0.000% |              0.389% |              0.000% |              0.389% |              0.000% |              0.389% |              0.000% |              0.778% |              0.000% |              0.778% |              0.389% |              0.389% |              0.000% |              0.000% |              0.000% |              0.389% |              0.000% |              0.000% |              0.389% |              0.389% |             61.045% | 
                         |             53.846% |              0.000% |             70.732% |            100.000% |              0.000% |            100.000% |              0.000% |              0.000% |             80.000% |            100.000% |            100.000% |            100.000% |              0.000% |             73.214% |              0.000% |             50.000% |              0.000% |              0.000% |              0.000% |             60.606% |             50.000% |              0.000% |            100.000% |              0.000% |            100.000% |             54.902% |            100.000% |             50.000% |              0.000% |            100.000% |              0.000% |            100.000% |             50.000% |             33.333% |            100.000% |              0.000% |            100.000% |              0.000% |             66.667% |              0.000% |            100.000% |             66.667% |            100.000% |            100.000% |            100.000% |             42.105% |            100.000% |            100.000% |            100.000% |            100.000% |              0.000% |            100.000% |            100.000% |             66.667% |            100.000% |            100.000% |            100.000% |             66.667% |            100.000% |            100.000% |             50.000% |              0.000% |            100.000% |            100.000% |              0.000% |            100.000% |              0.000% |            100.000% |             50.000% |            100.000% |             40.000% |             33.333% |             50.000% |            100.000% |             50.000% |              0.000% |            100.000% |              0.000% |            100.000% |              0.000% |            100.000% |              0.000% |            100.000% |              0.000% |             66.667% |            100.000% |             50.000% |              0.000% |              0.000% |              0.000% |            100.000% |              0.000% |              0.000% |            100.000% |            100.000% |                     | 
                         |              1.663% |              0.000% |              6.888% |              0.238% |              0.000% |              0.238% |              0.000% |              0.000% |              0.950% |              0.475% |              0.238% |              0.238% |              0.000% |              9.739% |              0.000% |              0.238% |              0.000% |              0.000% |              0.000% |              9.501% |              0.475% |              0.000% |              0.238% |              0.000% |              0.238% |              6.651% |              0.238% |              0.238% |              0.000% |              0.238% |              0.000% |              0.238% |              2.613% |              0.238% |              0.238% |              0.000% |              0.238% |              0.000% |              2.850% |              0.000% |              0.238% |              0.475% |              0.238% |              0.238% |              0.238% |              1.900% |              0.238% |              0.238% |              0.238% |              0.238% |              0.000% |              0.238% |              0.238% |              0.475% |              0.238% |              0.713% |              0.475% |              0.475% |              0.238% |              0.950% |              0.238% |              0.000% |              0.238% |              0.238% |              0.000% |              0.238% |              0.000% |              1.188% |              0.238% |              0.950% |              0.475% |              0.238% |              0.238% |              0.238% |              0.238% |              0.000% |              0.238% |              0.000% |              0.238% |              0.000% |              0.238% |              0.000% |              0.475% |              0.000% |              0.475% |              0.238% |              0.238% |              0.000% |              0.000% |              0.000% |              0.238% |              0.000% |              0.000% |              0.238% |              0.238% |                     | 
                         |             -0.936  |             -1.221  |              3.971  |              0.390  |             -0.610  |              0.390  |             -0.610  |             -0.610  |              0.948  |              0.779  |              0.390  |              0.390  |             -0.610  |              6.815  |             -0.610  |             -0.221  |             -0.610  |             -0.610  |             -0.610  |             -0.290  |             -0.442  |             -0.610  |              0.390  |             -0.610  |              0.390  |             -3.133  |              0.390  |             -0.221  |             -0.610  |              0.390  |             -0.610  |              0.390  |             -2.430  |             -0.831  |              0.390  |             -0.610  |              0.390  |             -0.610  |              1.012  |             -0.610  |              0.390  |              0.169  |              0.390  |              0.390  |              0.390  |             -3.599  |              0.390  |              0.390  |              0.390  |              0.390  |             -0.610  |              0.390  |              0.390  |              0.169  |              0.390  |              1.169  |              0.779  |              0.169  |              0.390  |              1.558  |             -0.221  |             -0.610  |              0.390  |              0.390  |             -0.610  |              0.390  |             -0.610  |              1.948  |             -0.221  |              1.558  |             -1.052  |             -0.831  |             -0.221  |              0.390  |             -0.221  |             -0.610  |              0.390  |             -1.221  |              0.390  |             -0.610  |              0.390  |             -0.610  |              0.779  |             -0.610  |              0.169  |              0.390  |             -0.221  |             -0.610  |             -1.221  |             -0.610  |              0.390  |             -0.610  |             -0.610  |              0.390  |              0.390  |                     | 
            -------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
                    Male |                  6  |                  2  |                 12  |                  0  |                  1  |                  0  |                  1  |                  1  |                  1  |                  0  |                  0  |                  0  |                  1  |                 15  |                  1  |                  1  |                  1  |                  1  |                  1  |                 26  |                  2  |                  1  |                  0  |                  1  |                  0  |                 23  |                  0  |                  1  |                  1  |                  0  |                  1  |                  0  |                 11  |                  2  |                  0  |                  1  |                  0  |                  1  |                  6  |                  1  |                  0  |                  1  |                  0  |                  0  |                  0  |                 11  |                  0  |                  0  |                  0  |                  0  |                  1  |                  0  |                  0  |                  1  |                  0  |                  0  |                  0  |                  1  |                  0  |                  0  |                  1  |                  1  |                  0  |                  0  |                  1  |                  0  |                  1  |                  0  |                  1  |                  0  |                  3  |                  2  |                  1  |                  0  |                  1  |                  1  |                  0  |                  2  |                  0  |                  1  |                  0  |                  1  |                  0  |                  1  |                  1  |                  0  |                  1  |                  1  |                  2  |                  1  |                  0  |                  1  |                  1  |                  0  |                  0  |                164  | 
                         |              0.173  |              1.913  |              0.988  |              0.390  |              0.957  |              0.390  |              0.957  |              0.957  |              0.461  |              0.779  |              0.390  |              0.390  |              0.957  |              2.129  |              0.957  |              0.063  |              0.957  |              0.957  |              0.957  |              0.003  |              0.125  |              0.957  |              0.390  |              0.957  |              0.390  |              0.494  |              0.390  |              0.063  |              0.957  |              0.390  |              0.957  |              0.390  |              0.689  |              0.591  |              0.390  |              0.957  |              0.390  |              0.957  |              0.146  |              0.957  |              0.390  |              0.024  |              0.390  |              0.390  |              0.390  |              1.750  |              0.390  |              0.390  |              0.390  |              0.390  |              0.957  |              0.390  |              0.390  |              0.024  |              0.390  |              1.169  |              0.779  |              0.024  |              0.390  |              1.558  |              0.063  |              0.957  |              0.390  |              0.390  |              0.957  |              0.390  |              0.957  |              1.948  |              0.063  |              1.558  |              0.568  |              0.591  |              0.063  |              0.390  |              0.063  |              0.957  |              0.390  |              1.913  |              0.390  |              0.957  |              0.390  |              0.957  |              0.779  |              0.957  |              0.024  |              0.390  |              0.063  |              0.957  |              1.913  |              0.957  |              0.390  |              0.957  |              0.957  |              0.390  |              0.390  |                     | 
                         |              3.659% |              1.220% |              7.317% |              0.000% |              0.610% |              0.000% |              0.610% |              0.610% |              0.610% |              0.000% |              0.000% |              0.000% |              0.610% |              9.146% |              0.610% |              0.610% |              0.610% |              0.610% |              0.610% |             15.854% |              1.220% |              0.610% |              0.000% |              0.610% |              0.000% |             14.024% |              0.000% |              0.610% |              0.610% |              0.000% |              0.610% |              0.000% |              6.707% |              1.220% |              0.000% |              0.610% |              0.000% |              0.610% |              3.659% |              0.610% |              0.000% |              0.610% |              0.000% |              0.000% |              0.000% |              6.707% |              0.000% |              0.000% |              0.000% |              0.000% |              0.610% |              0.000% |              0.000% |              0.610% |              0.000% |              0.000% |              0.000% |              0.610% |              0.000% |              0.000% |              0.610% |              0.610% |              0.000% |              0.000% |              0.610% |              0.000% |              0.610% |              0.000% |              0.610% |              0.000% |              1.829% |              1.220% |              0.610% |              0.000% |              0.610% |              0.610% |              0.000% |              1.220% |              0.000% |              0.610% |              0.000% |              0.610% |              0.000% |              0.610% |              0.610% |              0.000% |              0.610% |              0.610% |              1.220% |              0.610% |              0.000% |              0.610% |              0.610% |              0.000% |              0.000% |             38.955% | 
                         |             46.154% |            100.000% |             29.268% |              0.000% |            100.000% |              0.000% |            100.000% |            100.000% |             20.000% |              0.000% |              0.000% |              0.000% |            100.000% |             26.786% |            100.000% |             50.000% |            100.000% |            100.000% |            100.000% |             39.394% |             50.000% |            100.000% |              0.000% |            100.000% |              0.000% |             45.098% |              0.000% |             50.000% |            100.000% |              0.000% |            100.000% |              0.000% |             50.000% |             66.667% |              0.000% |            100.000% |              0.000% |            100.000% |             33.333% |            100.000% |              0.000% |             33.333% |              0.000% |              0.000% |              0.000% |             57.895% |              0.000% |              0.000% |              0.000% |              0.000% |            100.000% |              0.000% |              0.000% |             33.333% |              0.000% |              0.000% |              0.000% |             33.333% |              0.000% |              0.000% |             50.000% |            100.000% |              0.000% |              0.000% |            100.000% |              0.000% |            100.000% |              0.000% |             50.000% |              0.000% |             60.000% |             66.667% |             50.000% |              0.000% |             50.000% |            100.000% |              0.000% |            100.000% |              0.000% |            100.000% |              0.000% |            100.000% |              0.000% |            100.000% |             33.333% |              0.000% |             50.000% |            100.000% |            100.000% |            100.000% |              0.000% |            100.000% |            100.000% |              0.000% |              0.000% |                     | 
                         |              1.425% |              0.475% |              2.850% |              0.000% |              0.238% |              0.000% |              0.238% |              0.238% |              0.238% |              0.000% |              0.000% |              0.000% |              0.238% |              3.563% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              6.176% |              0.475% |              0.238% |              0.000% |              0.238% |              0.000% |              5.463% |              0.000% |              0.238% |              0.238% |              0.000% |              0.238% |              0.000% |              2.613% |              0.475% |              0.000% |              0.238% |              0.000% |              0.238% |              1.425% |              0.238% |              0.000% |              0.238% |              0.000% |              0.000% |              0.000% |              2.613% |              0.000% |              0.000% |              0.000% |              0.000% |              0.238% |              0.000% |              0.000% |              0.238% |              0.000% |              0.000% |              0.000% |              0.238% |              0.000% |              0.000% |              0.238% |              0.238% |              0.000% |              0.000% |              0.238% |              0.000% |              0.238% |              0.000% |              0.238% |              0.000% |              0.713% |              0.475% |              0.238% |              0.000% |              0.238% |              0.238% |              0.000% |              0.475% |              0.000% |              0.238% |              0.000% |              0.238% |              0.000% |              0.238% |              0.238% |              0.000% |              0.238% |              0.238% |              0.475% |              0.238% |              0.000% |              0.238% |              0.238% |              0.000% |              0.000% |                     | 
                         |              0.936  |              1.221  |             -3.971  |             -0.390  |              0.610  |             -0.390  |              0.610  |              0.610  |             -0.948  |             -0.779  |             -0.390  |             -0.390  |              0.610  |             -6.815  |              0.610  |              0.221  |              0.610  |              0.610  |              0.610  |              0.290  |              0.442  |              0.610  |             -0.390  |              0.610  |             -0.390  |              3.133  |             -0.390  |              0.221  |              0.610  |             -0.390  |              0.610  |             -0.390  |              2.430  |              0.831  |             -0.390  |              0.610  |             -0.390  |              0.610  |             -1.012  |              0.610  |             -0.390  |             -0.169  |             -0.390  |             -0.390  |             -0.390  |              3.599  |             -0.390  |             -0.390  |             -0.390  |             -0.390  |              0.610  |             -0.390  |             -0.390  |             -0.169  |             -0.390  |             -1.169  |             -0.779  |             -0.169  |             -0.390  |             -1.558  |              0.221  |              0.610  |             -0.390  |             -0.390  |              0.610  |             -0.390  |              0.610  |             -1.948  |              0.221  |             -1.558  |              1.052  |              0.831  |              0.221  |             -0.390  |              0.221  |              0.610  |             -0.390  |              1.221  |             -0.390  |              0.610  |             -0.390  |              0.610  |             -0.779  |              0.610  |             -0.169  |             -0.390  |              0.221  |              0.610  |              1.221  |              0.610  |             -0.390  |              0.610  |              0.610  |             -0.390  |             -0.390  |                     | 
            -------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|
            Column Total |                 13  |                  2  |                 41  |                  1  |                  1  |                  1  |                  1  |                  1  |                  5  |                  2  |                  1  |                  1  |                  1  |                 56  |                  1  |                  2  |                  1  |                  1  |                  1  |                 66  |                  4  |                  1  |                  1  |                  1  |                  1  |                 51  |                  1  |                  2  |                  1  |                  1  |                  1  |                  1  |                 22  |                  3  |                  1  |                  1  |                  1  |                  1  |                 18  |                  1  |                  1  |                  3  |                  1  |                  1  |                  1  |                 19  |                  1  |                  1  |                  1  |                  1  |                  1  |                  1  |                  1  |                  3  |                  1  |                  3  |                  2  |                  3  |                  1  |                  4  |                  2  |                  1  |                  1  |                  1  |                  1  |                  1  |                  1  |                  5  |                  2  |                  4  |                  5  |                  3  |                  2  |                  1  |                  2  |                  1  |                  1  |                  2  |                  1  |                  1  |                  1  |                  1  |                  2  |                  1  |                  3  |                  1  |                  2  |                  1  |                  2  |                  1  |                  1  |                  1  |                  1  |                  1  |                  1  |                421  | 
                         |              3.088% |              0.475% |              9.739% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              1.188% |              0.475% |              0.238% |              0.238% |              0.238% |             13.302% |              0.238% |              0.475% |              0.238% |              0.238% |              0.238% |             15.677% |              0.950% |              0.238% |              0.238% |              0.238% |              0.238% |             12.114% |              0.238% |              0.475% |              0.238% |              0.238% |              0.238% |              0.238% |              5.226% |              0.713% |              0.238% |              0.238% |              0.238% |              0.238% |              4.276% |              0.238% |              0.238% |              0.713% |              0.238% |              0.238% |              0.238% |              4.513% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              0.713% |              0.238% |              0.713% |              0.475% |              0.713% |              0.238% |              0.950% |              0.475% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              1.188% |              0.475% |              0.950% |              1.188% |              0.713% |              0.475% |              0.238% |              0.475% |              0.238% |              0.238% |              0.475% |              0.238% |              0.238% |              0.238% |              0.238% |              0.475% |              0.238% |              0.713% |              0.238% |              0.475% |              0.238% |              0.475% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |              0.238% |                     | 
            -------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|---------------------|


The above information could be brought into a spreadsheet program as Excel by merely copying (crtl+c) and pasting (crtl+v) into a cell. Then, the data could be manipulated into a table using the Text-to-Columns function of the program.


Figure 2. Copy and Paste output from CrossTable into Excel.


Figure 3. Go to the Data Tab and Set Option to Delimit by Character.


Figure 4. Set Delimit Character to |.


Figure 5. Result from Text-to-Table Process in Excel.



Interpretation:

From the cross tabulation, we found that 19.24% of Female respondents indicated a willingness-to-pay for collegiate t-shirts between Php250 to Php300. The rather close range in prices for a significant number of respondents (nearly one in five) indicates that part of the target customers of Urbanist Laboratory present downward price pressures on sellers for collegiate t-shirts.


Methods of Cross Tablulation: Two or more traits, xtabs.

Let's say we want to know the frequencies of individuals with more than two traits. Then we could use the base function xtabs. The syntax for xtabs is a formula, then the data source. For the Urbanist Laboratory case study, we want to look at the frequency of individuals in each gender who share Importance of Price and Importance of Style or Preferences. Here, we want to know how many women (UL.CT$Gender) state a particular importance for Style or Color (UL.CT$Imprt.Style.Color) are willing to buy at different prices (UL.CT$Imprt.Price). The code for this more in-depth analysis is:


xtabs(~ UL.CT$Imprt.Price + UL.CT$Imprt.Style + UL.CT$Gender, data=UL.CT)

The function xtabs will output a table that provides the frequencies of respondents from each gender with particular preferences for style and color relative to their corresponding price preferences.



            , , UL.CT$Gender = Female
        
            UL.CT$Imprt.Style
        UL.CT$Imprt.Price                                         1 (Least important reason for me to purchase clothing.)
        1 (Least important reason for me to purchase clothing.)                                                       0
        2                                                                                                             0
        3                                                                                                             0
        4                                                                                                             0
        5                                                                                                             0
        6                                                                                                             0
        7                                                                                                             0
        8                                                                                                             0
        9 (Most important reason for me to purchase clothing.)                                                        0
            UL.CT$Imprt.Style
        UL.CT$Imprt.Price                                          2  3  4  5  6  7  8
        1 (Least important reason for me to purchase clothing.)  0  0  0  0  0  0  1
        2                                                        0  0  0  0  0  0  2
        3                                                        0  0  0  0  1  1  1
        4                                                        0  0  0  1  0  1  2
        5                                                        1  0  0  1  1  6  3
        6                                                        0  0  0  2  2  7 15
        7                                                        0  0  0  4  4 11 12
        8                                                        0  0  0  4  5 21 18
        9 (Most important reason for me to purchase clothing.)   0  1  1  3  4 16 20
            UL.CT$Imprt.Style
        UL.CT$Imprt.Price                                         9 (Most important reason for me to purchase clothing.)
        1 (Least important reason for me to purchase clothing.)                                                      1
        2                                                                                                            1
        3                                                                                                            1
        4                                                                                                            1
        5                                                                                                            6
        6                                                                                                            7
        7                                                                                                           15
        8                                                                                                           15
        9 (Most important reason for me to purchase clothing.)                                                      38
        
        , , UL.CT$Gender = Male
        
            UL.CT$Imprt.Style
        UL.CT$Imprt.Price                                         1 (Least important reason for me to purchase clothing.)
        1 (Least important reason for me to purchase clothing.)                                                       0
        2                                                                                                             0
        3                                                                                                             0
        4                                                                                                             0
        5                                                                                                             0
        6                                                                                                             1
        7                                                                                                             0
        8                                                                                                             0
        9 (Most important reason for me to purchase clothing.)                                                        2
            UL.CT$Imprt.Style
        UL.CT$Imprt.Price                                          2  3  4  5  6  7  8
        1 (Least important reason for me to purchase clothing.)  0  0  0  0  0  0  0
        2                                                        0  0  0  0  0  1  0
        3                                                        0  0  1  1  0  0  1
        4                                                        0  0  1  0  0  0  0
        5                                                        0  0  0  1  1  6  3
        6                                                        0  0  0  2  6  4  2
        7                                                        0  0  2  0  7 12  6
        8                                                        0  1  0  1  4 10 10
        9 (Most important reason for me to purchase clothing.)   0  0  1  3  3 10 14
            UL.CT$Imprt.Style
        UL.CT$Imprt.Price                                         9 (Most important reason for me to purchase clothing.)
        1 (Least important reason for me to purchase clothing.)                                                      0
        2                                                                                                            2
        3                                                                                                            1
        4                                                                                                            1
        5                                                                                                            5
        6                                                                                                            4
        7                                                                                                           12
        8                                                                                                           10
        9 (Most important reason for me to purchase clothing.)                                                      12
        

To get the percentage distributions for respondent selections of importance between style and price all that would need to be done is to divide the xtab result by the total number of respondents. The following line of code describes how this is done. Take notice that it is merely dividing the function by the number of respondents (421).


xtabs(~ UL.CT$Imprt.Price + UL.CT$Imprt.Style + UL.CT$Gender, data=UL.CT)/421

The resulting output should look similar to the initial frequency table, now showing percentage distributions instead. The following output should result.


          , , UL.CT$Gender = Female

          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                         1 (Least important reason for me to purchase clothing.)
1 (Least important reason for me to purchase clothing.)                                             0.000000000
2                                                                                                   0.000000000
3                                                                                                   0.000000000
4                                                                                                   0.000000000
5                                                                                                   0.000000000
6                                                                                                   0.000000000
7                                                                                                   0.000000000
8                                                                                                   0.000000000
9 (Most important reason for me to purchase clothing.)                                              0.000000000
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   2
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.000000000
4                                                       0.000000000
5                                                       0.002375297
6                                                       0.000000000
7                                                       0.000000000
8                                                       0.000000000
9 (Most important reason for me to purchase clothing.)  0.000000000
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   3
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.000000000
4                                                       0.000000000
5                                                       0.000000000
6                                                       0.000000000
7                                                       0.000000000
8                                                       0.000000000
9 (Most important reason for me to purchase clothing.)  0.002375297
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   4
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.000000000
4                                                       0.000000000
5                                                       0.000000000
6                                                       0.000000000
7                                                       0.000000000
8                                                       0.000000000
9 (Most important reason for me to purchase clothing.)  0.002375297
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   5
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.000000000
4                                                       0.002375297
5                                                       0.002375297
6                                                       0.004750594
7                                                       0.009501188
8                                                       0.009501188
9 (Most important reason for me to purchase clothing.)  0.007125891
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   6
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.002375297
4                                                       0.000000000
5                                                       0.002375297
6                                                       0.004750594
7                                                       0.009501188
8                                                       0.011876485
9 (Most important reason for me to purchase clothing.)  0.009501188
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   7
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.002375297
4                                                       0.002375297
5                                                       0.014251781
6                                                       0.016627078
7                                                       0.026128266
8                                                       0.049881235
9 (Most important reason for me to purchase clothing.)  0.038004751
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   8
1 (Least important reason for me to purchase clothing.) 0.002375297
2                                                       0.004750594
3                                                       0.002375297
4                                                       0.004750594
5                                                       0.007125891
6                                                       0.035629454
7                                                       0.028503563
8                                                       0.042755344
9 (Most important reason for me to purchase clothing.)  0.047505938
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                         9 (Most important reason for me to purchase clothing.)
1 (Least important reason for me to purchase clothing.)                                            0.002375297
2                                                                                                  0.002375297
3                                                                                                  0.002375297
4                                                                                                  0.002375297
5                                                                                                  0.014251781
6                                                                                                  0.016627078
7                                                                                                  0.035629454
8                                                                                                  0.035629454
9 (Most important reason for me to purchase clothing.)                                             0.090261283

, , UL.CT$Gender = Male

          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                         1 (Least important reason for me to purchase clothing.)
1 (Least important reason for me to purchase clothing.)                                             0.000000000
2                                                                                                   0.000000000
3                                                                                                   0.000000000
4                                                                                                   0.000000000
5                                                                                                   0.000000000
6                                                                                                   0.002375297
7                                                                                                   0.000000000
8                                                                                                   0.000000000
9 (Most important reason for me to purchase clothing.)                                              0.004750594
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   2
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.000000000
4                                                       0.000000000
5                                                       0.000000000
6                                                       0.000000000
7                                                       0.000000000
8                                                       0.000000000
9 (Most important reason for me to purchase clothing.)  0.000000000
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   3
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.000000000
4                                                       0.000000000
5                                                       0.000000000
6                                                       0.000000000
7                                                       0.000000000
8                                                       0.002375297
9 (Most important reason for me to purchase clothing.)  0.000000000
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   4
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.002375297
4                                                       0.002375297
5                                                       0.000000000
6                                                       0.000000000
7                                                       0.004750594
8                                                       0.000000000
9 (Most important reason for me to purchase clothing.)  0.002375297
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   5
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.002375297
4                                                       0.000000000
5                                                       0.002375297
6                                                       0.004750594
7                                                       0.000000000
8                                                       0.002375297
9 (Most important reason for me to purchase clothing.)  0.007125891
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   6
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.000000000
4                                                       0.000000000
5                                                       0.002375297
6                                                       0.014251781
7                                                       0.016627078
8                                                       0.009501188
9 (Most important reason for me to purchase clothing.)  0.007125891
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   7
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.002375297
3                                                       0.000000000
4                                                       0.000000000
5                                                       0.014251781
6                                                       0.009501188
7                                                       0.028503563
8                                                       0.023752969
9 (Most important reason for me to purchase clothing.)  0.023752969
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                                   8
1 (Least important reason for me to purchase clothing.) 0.000000000
2                                                       0.000000000
3                                                       0.002375297
4                                                       0.000000000
5                                                       0.007125891
6                                                       0.004750594
7                                                       0.014251781
8                                                       0.023752969
9 (Most important reason for me to purchase clothing.)  0.033254157
          UL.CT$Imprt.Style
UL.CT$Imprt.Price                                         9 (Most important reason for me to purchase clothing.)
1 (Least important reason for me to purchase clothing.)                                            0.000000000
2                                                                                                  0.004750594
3                                                                                                  0.002375297
4                                                                                                  0.002375297
5                                                                                                  0.011876485
6                                                                                                  0.009501188
7                                                                                                  0.028503563
8                                                                                                  0.023752969
9 (Most important reason for me to purchase clothing.)                                             0.028503563
        

Interpretation

From the cross tabulations, we find that style and price are competing factors in the decision to purchase apparel. Both female and male respondents cite both factors as non-trivial reasons for the purchase of clothing. A look at the percentage distributions for importance of style and price in the purchasing decisions of target customers, we find that for female respondents there appears to be a relationship between the importance of style and price. At this, a correlation analysis would allow for more insights to be drawn about the preferences of target customers along the other qualitative questions asked in the survey.

Conclusion.

In this case study we discussed how to bring data into an R session. From the data set, we changed the names of certain columns. These columns were the subject of several methods of cross tabulation. As an introduction to the R Statistics Environment, this module on cross tabulation methods shows us the versatility and expediency of the program in statistical analyses.

I will continue to add more modules as the year progresses. If your organization would like a live tutorial or a series of analyses done on any data sets, please contact me by email.


Back to Projects and Publications page.

View Tableau Visualizations page.

Back to Projects and Publications
Data Cleaning &
Word Clouds
Tableau Visualizations
Back to Top
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.