SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  How to specify a specific cell format using spss.BasePivotTable in R

    Posted Fri September 08, 2023 06:00 PM

    Hi,

    I would like to format table cells in R using BasePivotTable functions, but I cannot find information on how to format a number to a specific number of decimal places. Is there a way to do that?

    Many thanks in advance.

    Adam



    ------------------------------
    Adam Lund
    ------------------------------


  • 2.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Fri September 08, 2023 06:34 PM
    The R package doesn't provide as much formatting control in pivot tables as its Python equivalent.  You can use the CellText formatspec parameter to pick a general format, which will have a reasonable number of decimal places for the chosen format, and you can use a format for a variable in the SPSS variable dictionary, but the SetDecimalDigits Python api does not have an equivalent in R.  You could convert a value to a formatted string in your R code and use it for a pivot table cell, but that has some downsides,  Sorry.

    --





  • 3.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Tue September 12, 2023 07:21 AM

    Hi Jon,

    Thank you again for your quick response.

    I have read that you can use the format of a variable in an active dataset when creating custom pivot tables. Based on your response, do you know if it is possible to use the spssdictionary.CreateSPSSDictionary function to create an SPSS dictionary variable (stored in an R variable) just for formatting table cells using, for example, SetCellValue? And, if so, how this would be accomplished?

    Many thanks again for all your help.

    Kind regards,

    Adam

     



    ------------------------------
    Adam Lund
    ------------------------------



  • 4.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Tue September 12, 2023 09:12 AM
    The SetDefaultFormatSpec api can reference a variable by index in the active dataset, but it works like the formatting you see in procedure output such as from Descriptives.  So if you, for example, specify Mean as the cell format but reference a variable that has 0 decimals, you would get cells that have two decimal places.

    However, that applies to the whole table, and would be rather a pain.  A much easier way to do this would be to create your table without that and then using the OUTPUT MODIFY command to set the specific cell formats you want.  For example, for a DESCRIPTIVES table, you could submit
    OUTPUT MODIFY
      /SELECT TABLES
      /IF COMMANDS=["Descriptives(1)"] LABELS=[EXACT("Descriptive Statistics")] INSTANCES=[1]
      /TABLECELLS SELECT=[MEAN] SELECTDIMENSION=COLUMNS SELECTCONDITION=ALL FORMAT="F.4" APPLYTO=CELL.

    --





  • 5.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Tue September 12, 2023 11:51 AM
    Edited by Adam Lund Tue September 12, 2023 11:52 AM

    Hi Jon,

    I am having some difficulty with understanding how to use this OUTPUT MODIFY command. Let me describe what I have in more detail:

    I have a table - generated using R code - that contains what I believe are useful descriptive statistics when running a Brunner-Munzel test. The table has the following columns:

    gender (i.e., the name of the independent variable selected via the GUI), N (i.e., the number of cases in each group), Mean, Std Dev., 25th percentile, median, 75th percentile, mean rank. 

    The table has 2 rows:

    male, female (i.e., the two groups of the independent variable)

    This table is stored as an R dataframe called, let's say, tbl_desc. 

    I can use the spsspivottable.Display function and generate a very nice table. However, there are some changes that would be ideal. One of these is that the column displaying the number of cases in each group should be a whole number. With respect to the OUTPUT MODIFY syntax you described, I am not sure how to use this command to "grab" the result of BasePivotTable and modify the N column.

    Any instruction on how this would be accomplished would be most appreciated. Of course, if I have misunderstood what you are describing in any way, please just let me know.

    Kind regards,

    Adam



    ------------------------------
    Adam Lund
    ------------------------------



  • 6.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Tue September 12, 2023 01:01 PM

    jkpeck@gmail.com in case my email address didn't come through.



    ------------------------------
    Jon Peck
    ------------------------------



  • 7.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Wed September 13, 2023 10:15 AM

    Hi Jon,

    I have just sent you an email.

    Many thanks again for all your help.

    Kind regards,

    Adam



    ------------------------------
    Adam Lund
    ------------------------------



  • 8.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Wed September 13, 2023 10:33 AM
    Can you send me an spv (Viewer) file containing a table you want to modify?  

    --





  • 9.  RE: How to specify a specific cell format using spss.BasePivotTable in R

    Posted Wed September 13, 2023 11:09 AM

    Hi Jon,

    Just sent.

    Many thanks,

    Adam



    ------------------------------
    Adam Lund
    ------------------------------