extract label from labelled column in database

i want to extract label from the labelelled column from the database. so here i want to extract labels from columns all, vs1, am1 from the data df.

output can be a list of labels ("all","version","amp")

df <- mtcars 
df$vs<-factor(df$vs, levels=c(1,0), labels = c("version","others")) 
df$am<-factor(df$am, levels=c(1,0), labels = c("AMP","others")) 
df$all<- 1 
df$am1<-ifelse(df$am == 'AMP', 1, NA) 
#"Cuts will be labelled like below definition" 
dfl <- list(df$all,df$vs1,df$am1)

I don't understand the question. What is dat, same thing as df? What is val_lab()?

just updated everything

Still not sure I fully understand, but I think what you want is simply:

lapply(dfl, val_lab)
#> [[1]]
#> All 
#>   1 
#> [[2]]
#> version 
#>       1 
#> [[3]]
#> AMP 
#>   1

or to keep just the names:

       function(x) names(val_lab(x)))
#> [[1]]
#> [1] "All"
#> [[2]]
#> [1] "version"
#> [[3]]
#> [1] "AMP"

(and you can switch lapply() to sapply() to get them as a vector)

This topic was automatically closed 7 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.