0

In REDCap, categorical variables are exported as numbers with labels, and yes/no fields are exported as 0/1 with labels. REDCap offers a R script to transform those variables (actually to create new ones) as factors with labels. The R script is like this:

dataset$sex = factor(dataset$sex,levels=c("0","1"))
dataset$indic1 = factor(dataset$indic1,levels=c("0","1"))
dataset$indic2 = factor(dataset$indic2,levels=c("0","1"))

levels(dataset$sex)=c("Female","Male")
levels(dataset$indic1)=c("Unchecked","Checked")
levels(dataset$indic2)=c("Unchecked","Checked")

label(dataset$sex)="Sex"
label(dataset$indic1)="Indication 1"
label(dataset$indic2)="Indication 2"

Is there a way to either export those variables directly as characters (I tried "stringsAsFactors = FALSE" in the "read.csv" call but it doesn't work), or to transform multiple variables into factors with the same label? In the example above, how would one transform indic1 and indic2 into factors and apply the labels 0 = "Unchecked", 1 = "Checked"?

DrNumeri
  • 5
  • 4

0 Answers0