SetCellsByColumn Method (R)
.SetCellsByColumn(object,collabels,cells). Sets cell
values for the column specified by a set of categories, one for each
column dimension. The argument object is a reference to
the associated BasePivotTable
object. The argument collabels specifies
the set of categories that defines the column--a single value or a
list. The argument cells is a list of cell values. Column categories
and cell values must be specified as CellText objects
(one of CellText.Number
, CellText.String
, CellText.VarName
,
or CellText.VarValue
).
- For tables with multiple column dimensions, the order of categories in the collabels argument is the order in which their respective dimensions were added (appended or inserted) to the table. For example, given two column dimensions coldim1 and coldim2 added in the order coldim1 and coldim2, the first element in collabels should be the category for coldim1 and the second the category for coldim2.
- You can only use the
SetCellsByColumn
method with pivot tables that have one row dimension.
Example
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
rowdim=BasePivotTable.Append(table,Dimension.Place.row,"rowdim")
coldim1=BasePivotTable.Append(table,Dimension.Place.column,"coldim-1")
coldim2=BasePivotTable.Append(table,Dimension.Place.column,"coldim-2")
cat1=spss.CellText.String("coldim1:A")
cat2=spss.CellText.String("coldim1:B")
cat3=spss.CellText.String("coldim2:A")
cat4=spss.CellText.String("coldim2:B")
cat5=spss.CellText.String("C")
cat6=spss.CellText.String("D")
BasePivotTable.SetCategories(table,coldim1,list(cat1,cat2))
BasePivotTable.SetCategories(table,coldim2,list(cat3,cat4))
BasePivotTable.SetCategories(table,rowdim,list(cat5,cat6))
BasePivotTable.SetCellsByColumn(table,list(cat1,cat3),
lapply(list(11,21),spss.CellText.Number))
BasePivotTable.SetCellsByColumn(table,list(cat1,cat4),
lapply(list(12,22),spss.CellText.Number))
BasePivotTable.SetCellsByColumn(table,list(cat2,cat3),
lapply(list(13,23),spss.CellText.Number))
BasePivotTable.SetCellsByColumn(table,list(cat2,cat4),
lapply(list(14,24),spss.CellText.Number))
- In this example, Number objects are used to specify numeric values
for the cells. Values will be formatted using the table's default
format. Instances of the
BasePivotTable
class have an implicit default format ofGeneralStat
. You can change the default format using the SetDefaultFormatSpec method, or you can override the default by explicitly specifying the format, as in:spss.CellText.Number(22,formatSpec.Correlation)
. See the topic CellText.Number Class (R) for more information.

Examples of using the SetCellsByColumn
method
are most easily understood in the context of going through the steps
to create a pivot table. See the topic General Approach to Creating Pivot Tables (R) for more information.