SetCellsByRow Method (R)
.SetCellsByRow(object,rowlabels,cells). Sets cell
values for the row specified by a set of categories, one for each
row dimension. The argument object is a reference to the
associated BasePivotTable
object. The argument rowlabels specifies
the set of categories that defines the row--a single value or a list.
The argument cells is a list of cell values. Row 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 row dimensions, the order of categories in the rowlabels argument is the order in which their respective dimensions were added (appended or inserted) to the table. For example, given two row dimensions rowdim1 and rowdim2 added in the order rowdim1 and rowdim2, the first element in rowlabels should be the category for rowdim1 and the second the category for rowdim2.
- You can only use the
SetCellsByRow
method with pivot tables that have one column dimension.
Example
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
coldim=BasePivotTable.Append(table,Dimension.Place.column,"coldim")
rowdim1=BasePivotTable.Append(table,Dimension.Place.row,"rowdim-1")
rowdim2=BasePivotTable.Append(table,Dimension.Place.row,"rowdim-2")
cat1=spss.CellText.String("rowdim1:A")
cat2=spss.CellText.String("rowdim1:B")
cat3=spss.CellText.String("rowdim2:A")
cat4=spss.CellText.String("rowdim2:B")
cat5=spss.CellText.String("C")
cat6=spss.CellText.String("D")
BasePivotTable.SetCategories(table,rowdim1,list(cat1,cat2))
BasePivotTable.SetCategories(table,rowdim2,list(cat3,cat4))
BasePivotTable.SetCategories(table,coldim,list(cat5,cat6))
BasePivotTable.SetCellsByRow(table,list(cat1,cat3),
lapply(list(11,12),spss.CellText.Number))
BasePivotTable.SetCellsByRow(table,list(cat1,cat4),
lapply(list(21,22),spss.CellText.Number))
BasePivotTable.SetCellsByRow(table,list(cat2,cat3),
lapply(list(31,32),spss.CellText.Number))
BasePivotTable.SetCellsByRow(table,list(cat2,cat4),
lapply(list(41,42),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 SetCellsByRow
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.