I was trying to generate a dialog box where a user can select elements to keep, however the item I want to keep is a character but it looks like R is giving them numeric values based on their alphabetical rank. Here's an example (I would prefer the list in the dialog box to be 1:Red, 2:Yellow, 3: Blue instead it's giving me 2, 3, 1):
library(dplyr)
library(tcltk)
library(utils)
x<-c(1,2,5)
y<-c(7,2.2,8)
c<-c("red", "yellow", "blue")
df<-as.data.frame(cbind(x,y,c),stringsasfactors=FALSE)
answer<-tk_select.list(df$c, preselect = NULL, multiple = TRUE,
            title = "Select items to keep:")
selected_df<-filter(df, c %in% answer)
selected_df
				
                        
We can create the
data.frameasWith this, the output of
selected_dfisNOTE:
stringsasfactorsis not equal tostringsAsFactors. So, thecharactercolumns remain asfactorclassAlso,
as.data.frame(cbind, would have unnecessary issues ascbindreturns amatrixandmatrixcan have only a singleclassi.e. all the columns are converted tocharacterclass because the values in 'c' arecharacter. When we useas.data.framewithstringsAsFactors = FALSE, it does createcharacterclass butnumericcolumns should remain numeric