[R] R GUI tklistbox get value

jpara3 j.para.fernandez at hotmail.com
Mon Jul 20 12:29:07 CEST 2015


Hi, i have a dataframe, dat, with 2 variables, one and two.

I want to print in R the mean of the selected variable of the dataframe. You
can select it with a tklistbox, but when you click OK button, the mean is
not displayed, just NA


########


one<-c(5,5,6,9,5,8)
two<-c(12,13,14,12,14,12)
dat<-data.frame(uno,dos)

require(tcltk)
tt<-tktoplevel()
tl<-tklistbox(tt,height=4,selectmode="single")
tkgrid(tklabel(tt,text="Selecciona la variable para calcular media"))
tkgrid(tl)
for (i in (1:4))
{
    tkinsert(tl,"end",colnames(dat[i]))
}
 
OnOK <- function()
{

  selecvar <- dat[as.numeric(tkcurselection(tl))+1]
   
  print(mean(selecvar))

}
OK.but <-tkbutton(tt,text="   OK   ",command=OnOK)
tkgrid(OK.but)
tkfocus(tt)

#################

Can someone please help me?? Thanks!!! 



--
View this message in context: http://r.789695.n4.nabble.com/R-GUI-tklistbox-get-value-tp4710064.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list