Error in eval(predvars, data, env) : object 'agedx' not found

I am a newbie to R and am trying to read in data from some SAS datasets into R and create a table using tableby function. My code is below. So far I have been successful in doing stats on categorical variables but having trouble with continuous stats. When I try doing frequencies on TRTSLPCATN or PHENO it works fine but when I try to do stats on the continuous variable AGEDX I get the error message above. I have confirmed that the variable exists in ANTRT3 so not sure what the problem is. Any advice would be appreciated.

setwd("C:/Users/laruer/OneDrive - Navitas Life Sciences/Desktop/R projects")
antrt <- read_sas("antrt.sas7bdat")
adpheno <- read_sas("adpheno.sas7bdat")
antrt1 <- left_join(antrt, select(adpheno, c(USUBJID, PHEDESRN)), by = "USUBJID")
antrt2 <- filter(antrt1, !(EVTCAT %in% c(1:4)))
antrt3 <- antrt2 %>% mutate(compfl = case_when(EVTCAT == 5 ~ 1,
TRUE ~ 2),
pheno = case_when(PHEDESRN == 1 ~ 1,
PHEDESRN == 2 ~ 2,
TRUE ~ 3),
trtslpcatn = case_when(grepl("Decrease", TRTSLPCAT) == TRUE ~ 1,
TRTSLPCAT == "Stable" ~ 2,
grepl("Increase", TRTSLPCAT) == TRUE ~ 3))
names <- c('compfl','trtslpcatn','pheno')
antrt3[,names] <- lapply(antrt3[,names], factor)
antrt3 = apply_labels(antrt3,pheno = "Phenotype",trtslpcatn = "LVMI Slope Category")
antrt3$pheno <- factor(antrt3$pheno,
levels = c(1,2,3),
labels = c("Classic","Later onset","Other"))
antrt3$trtslpcatn <- factor(antrt3$trtslpcatn,
levels = c(1,2,3),
labels = c("Decrease >5 g/m2 per year","Stable","Increase >5 g/m2 per year"))
tab_controls <- tableby.control(test = FALSE, total = FALSE,
numeric.stats=c("N", "meansd", "medianq1q3", "range"),
stats.labels=list(N='N', meansd="Median (SD)", medianq1q3="Median (Q1, Q3)", range = "Min - Max"))
table_dem <- tableby(compfl ~ trtslpcatn + agedx, data = antrt3, control = tab_controls)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.