On Sat, 6 Sep 2014 08:21:19 -0700 William Dunlap <wdun...@tibco.com> wrote:
> testdataextract1<-switch(menu(c(unique(levels(testdata[,1]))),graphics=FALSE,title='Select > something')) The switch function does not work the way you are expecting it to. Read help("switch") and read the introduction to R that comes with R. You probably want to use the output of menu() to extract a row of testdata with testdata[outputOfMenu,]. (How could testdataextract1 contain anything in the 2nd or 3rd columns of testdata if the expression producing testdataextract1 does not contain any reference to that column?)
I tried:
testdataextract1<-function (testdata) {
+ selectionresult<-switch(menu(c(unique(levels(testdata[,1]))),graphics=FALSE,title='Select something')) + return (testdata[selectionresult,]) + }
testdataextract1(testdata)
Select something 1: text test1 2: text test2 3: text test3 Selection: 2 [1] variablea variableb variablec <0 rows> (or 0-length row.names) Why does this error occur? Although the menu must show only unique values to be chosen, the resultant output must show all values that match the chosen value in this example: text test2 other texty 200 text test2 other texty 700 text test2 other texty 300 text test2 other texty 250 ______________________________________________ R-help@r-project.org mailing list 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.