I have one dataset, called unchf_data
, it contains participants where some have answered a questionnaire and some have not. I want to make a descriptive table (table 1) where I have the columns (Total
, No answer
, Answer
).
Making new column subgroup, for a table 1. # if PREG column answered "Yes" or 1, then in final cohort.
`unchf_data2 <- unchf_data2[!(unchf_data2$PREG == "0"),]`# removing all where pregnancy is 0. If no pregnancy then no chance of having an APO.
unchf_data2<- unchf_data2[!c(is.na(unchf_data2$HYPTPREG) == "TRUE" &
is.na(unchf_data2$DIABPREG) == "TRUE" &
is.na(unchf_data2$BABYLT5LBS) == "TRUE" &
is.na(unchf_data2$BORN3WKSERLY) == "TRUE" &
is.na(unchf_data2$PREECLMP) == "TRUE" &
is.na(unchf_data2$BABYGT9LBS) == "TRUE"),] # removing all that have missing in all APO variables.
`unchf_data2$subgroup <- 1` # creating new variable - subgroup which has 1 in all
unchf_data2$subgroup <- factor(unchf_data2$subgroup, levels = c(1))
`subgroup2 <- unchf_data2$subgroup` # making the new vector from subgroup variable
library(qpcR)
unchf_data <- qpcR:::cbind.na(subgroup2, unchf_data) # Binds our new vector with length of 10375 to our data set with length of 44174, filling in NA values for everything longer than the vector.
unchf_data$subgroup2[is.na(unchf_data$subgroup2) == "TRUE"] <- 0 # recoding all NA values to 0
unchf_data$subgroup2 <- factor(unchf_data$subgroup2, levels = c(0,1), labels = c("No answer", "Answer")) # converting variable to factor.
summary(unchf_data$subgroup2) # No answer 33799, Answer 10375
My problem now is that apparently the new subgroup2 variable does not line up with the original dataset. Is there another way I can do this? The reason I want a new variable in the dataset is because I'm using the UnivariateTable function from the Publish Package