I want to get labels from the data dynamically, for example dfl2, it should fetch "All","Media","BT","Team B" etc. and same as for for dfl1 should be "All", "Media", "BT" etc. and also for dfl3.
Its perfectly working if i give banner definition like below like below
dfl1 <- c("all","vs1","am1")
labels <- names(sapply(dfl1, function(x) {df[x] %>% val_lab()}))
but i want to give banner definition like below, it should work for below
dfl3 <- list(df$all,df$vs1,df$carb1)
library(expss)
df <- mtcars
df$vs<-factor(df$vs, levels=c(1,0), labels = c("Media","Non-Media"))
df$am<-factor(df$am, levels=c(1,0), labels = c("Local","Outsider"))
df$gear<-factor(df$gear, levels=c(3,4,5), labels = c("BT","TA","PA"))
df$carb<-factor(df$carb, levels=c(1,2,3,4,6,8), labels = c("Team A","Team B","Team C","Team D","Team E","Team F"))
df$all<- 1
df$vs1<-ifelse(df$vs=='Media',1,NA)
df$am1<-ifelse(df$am == 'Local', 1, NA)
df$gear1<-ifelse(df$gear == 'BT', 1, NA)
df$carb1<-ifelse(df$carb == 'Team B', 1, NA)
expss::val_lab(df$all)<-c("All"=1)
expss::val_lab(df$vs1)<-c("Media"=1)
expss::val_lab(df$am1)<-c("BT"=1)
expss::val_lab(df$gear1)<-c("Team B"=1)
dfl2 <- list(df$all,df$vs1,df$am1,df$gear1)
dfl1 <- list(df$all,df$vs1,df$am1)
dfl3 <- list(df$all,df$vs1,df$carb1)
listt = dfl1
d1 <- tail(sapply(df, function(x) names(val_lab(x))),length(listt))
I have tried below options but not working
d1 <- sapply(df1, function(x) names(val_lab(x)))[names(dfl1)]
lapply(dfl2,function(x) {df[x] |> var_lab()})
output should be labels from data like "All", "Media", "BT" for dfl1 and "All","Media","BT","Team B" for dfl2 etc.