[R] R GUI tklistbox get value

John Fox jfox at mcmaster.ca
Tue Jul 21 00:31:58 CEST 2015


Dear j.para.fernandez,

Try

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

Omitting the comma returns a one-column data frame, not a numeric vector.

I hope this helps,
 John

------------------------------------------------
John Fox, Professor
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Mon, 20 Jul 2015 03:29:07 -0700 (PDT)
 jpara3 <j.para.fernandez at hotmail.com> wrote:
> 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.
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list