[R] Difficultes with grep
jim holtman
jholtman at gmail.com
Fri Jul 11 20:54:42 CEST 2008
I think this is what you want
> table <- sample(LETTERS[1:5], 20,TRUE)
>
> name <- "A"
>
> myfun <- function(name) {
+ r <- grep (name, table )
+ return (r) }
>
> myfun(name)
[1] 4 7 14 18
> table
[1] "E" "B" "D" "A" "B" "B" "A" "B" "E" "B" "C" "C" "C" "A" "E" "D"
"D" "A" "D" "C"
>
On Fri, Jul 11, 2008 at 1:57 PM, Fran100681 <franaruto at hotmail.it> wrote:
>
> Hello everybody!
>
> I'm using R and I have a little problem about function "grep". I 've got to
> make a new function in which "grep" is present. So the first argument of
> "grep" is the string we want to find,ok..but in this case I define a
> function "x" before , x receives an argument in a object "name" (for
> instance), then inside function "x" ,i define a grep.. so i want to set as
> pattern (1st argument of grep) what i put in "name" and not the string
> "name"... how do i do that?
>
> ex:
> name <- "Tom"
>
> myfun <- function(name) {
> r <- grep ("name", table )
> return (r) }
> It returns nothing because it searches the word "name" in "table" rather
> "Tom"...
> I hope to receive some little help because this is stopping me in my projcet
> :/ ... i m'not able to reach a solution! Thanks a lot!
> --
> View this message in context: http://www.nabble.com/Difficultes-with-grep-tp18409347p18409347.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list