I want to put in selectInput of Rshiny all the levels of a variable (which is character) with the few lines of code.
var<-c("a","a","b","b","c","d")
I want to have something like this
c("a"="a", "b"="b", "c"="c", "d"="d")
then like this
c("Whole a"="="a", "Whole b"="b", "Whole c"="c", "Whole d=","d")
"Whole a"
for example means I want to write complete names of the levels (begining with a capital letter and having space between two words).
The first solution I thought of is to use paste()
.
paste (unique(var),"=",unique(var),collapse = ",")
which give as ouput
"a = a, b= b, c = c, d = d"
However, I know these codes are insufficient
Do you want to create a named vector? something like this.
setNames(unique(var), paste('Whole', unique(var)))
#Whole a Whole b Whole c Whole d
# "a" "b" "c" "d"