seqrecode | R Documentation |
Utilities for recoding factors or state sequence objects created with seqdef
.
seqrecode(seqdata, recodes, otherwise = NULL,
labels = NULL, cpal = NULL)
recodef(x, recodes, otherwise=NULL, na=NULL)
seqdata |
The state sequence object to be recoded (created with |
recodes |
A |
otherwise |
|
labels |
optional state labels used for the color legend of TraMineR's graphics. If |
cpal |
an optional color palette for representing the newly defined alphabet in graphics. If |
x |
A factor to be recoded. |
na |
Character vector. If not |
The recoded factor or state sequence object.
Matthias Studer (with Gilbert Ritschard for the help page)
seqdef
to create a state sequence object.
## Recoding a state sequence object with seqrecode
data(actcal)
## Creating a state sequence object
actcal.seq <- seqdef(actcal,13:24, labels=c("> 37 hours", "19-36 hours",
"1-18 hours", "no work"))
## Regrouping states B and C and setting the whole alphabet to A BC D
actcal.new <-seqrecode(actcal.seq,
recodes = list("A"="A", "BC"=c("B", "C"), "D"="D"))
## Crosstabulate the first column of the recoded and
## original state sequence objects
table(actcal.new[,1], actcal.seq[,1])
## Same as before but using automatically original
## codes for unspecified states.
actcal.new2 <-seqrecode(actcal.seq,
recodes = list("BC"=c("B", "C")))
table(actcal.new2[,1], actcal.seq[,1])
## Same as before but using otherwise
actcal.new3 <-seqrecode(actcal.seq, recodes = list("A"="A", "D"="D"),
otherwise="BC")
table(actcal.new3[,1], actcal.seq[,1])
## Recoding factors
## Recoding the marital status to oppose married to all other case
maritalstatus <- recodef(actcal$civsta00,
recodes=list("Married"="married"), otherwise="Single")
summary(maritalstatus)
table(maritalstatus, actcal$civsta00)
## Recoding the number of kids in the household
## -2 is a missing value
nbkids <- recodef(actcal$nbkid00,
recodes=list("None"=0, "One"=1, "Two or more"=2:10), na=-2)
table(nbkids, actcal$nbkid00, useNA="always")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.