[R] sequential input script dataframe process functionality

rl at openmailbox.org rl at openmailbox.org
Mon Sep 8 11:12:49 CEST 2014


On Sat, 6 Sep 2014 08:21:19 -0700
William Dunlap <wdunlap at 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



More information about the R-help mailing list