
decode
converts from the numeric (column IDs) representation to
readable item labels. decode
is used by LIST
.
encode
converts from readable item labels to an itemMatrix using a
given coding. With this method it is possible to create several compatible
itemMatrix
objects (i.e., use the same binary representation for
items) from data.
recode
recodes an itemMatrix
object so its coding is compatible
with another object or the matrix follows a certain order of items.
decode(x, ...)
## S3 method for class 'list':
decode(x, itemLabels)
## S3 method for class 'numeric':
decode(x, itemLabels)encode(x, ...)
## S3 method for class 'list':
encode(x, itemLabels, itemMatrix = TRUE)
## S3 method for class 'character':
encode(x, itemLabels, itemMatrix = TRUE)
## S3 method for class 'numeric':
encode(x, itemLabels, itemMatrix = TRUE)
recode(x, ...)
## S3 method for class 'itemMatrix':
recode(x, itemLabels = NULL, match = NULL)
encode
) or of numeric (for decode
), or
an object of class itemMatrix
(for recode
).itemLabels
vector can be obtained from itemMatrix
,
transactions
anitemMatrix
otherwise
an object of the same class as x
is returned.itemMatrix
object whose item coding x
should match.recode
always returns an object
of class itemMatrix
.
For encode
with itemMatrix = TRUE
an object
of class itemMatrix
is returned.
Otherwise the result is of the same type as x
, e.g., a
list or a vector.LIST
,
associations-class
,
itemMatrix-class
data("Adult")
## Example 1: Manual decoding
## get code
iLabels <- itemLabels(Adult)
head(iLabels)
## get undecoded list and decode in a second step
list <- LIST(Adult[1:5], decode = FALSE)
list
decode(list, itemLabels = iLabels)
## Example 2: Manually create an itemMatrix
data <- list(
c("income=small", "age=Young"),
c("income=large", "age=Middle-aged")
)
iM <- encode(data, iLabels)
iM
inspect(iM)
## use the itemMatrix to create transactions
as(iM, "transactions")
## Example 3: use recode
## select first 100 transactions and all education-related items
sub <- Adult[1:100, itemInfo(Adult)$variables == "education"]
itemLabels(sub)
image(sub)
## recode to match Adult again
sub.recoded <- recode(sub, match = Adult)
image(sub.recoded)
Run the code above in your browser using DataLab