d <- data.frame(Choices=c("One","Two","One","Three"), X=1:4) i <- 1 # possible output of menu(unique(d$Choices)) d[ d$Choices[i] == d$Choices, ] # Choices X #1 One 1 #3 One 3
I believe this sort of thing is covered in the Introduction to R pdf that comes with R. It is worth reading. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Sep 8, 2014 at 8:13 AM, <r...@openmailbox.org> wrote: > On Mon, 8 Sep 2014 07:55:23 -0700 > William Dunlap <wdun...@tibco.com> wrote: > >> Again, feed the output of menu() directly into "[". Do not use >> switch(). Bill Dunlap > > > The function was changed to: > > testdataextract1<-function (testdata) { > selectionresult<-menu(c(unique(levels(testdata[,1]))),graphics=FALSE,title='Select > something') return (testdata[selectionresult,]) > } > testdataextract1(testdata) > >> testdataextract1(testdata) > > Select something > > 1: text test1 > 2: text test2 > 3: text test3 > > Selection: 2 > variablea variableb variablec > 2 text test2 other texty 200 > > However, how to adjust the function 'return' so that _all_ values that > match the selected value from the menu are returned (as below)? > >>> >>> 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.