Re: [R] Difficultes with grep

From: jim holtman <jholtman_at_gmail.com>
Date: Fri, 11 Jul 2008 14:54:42 -0400

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?

______________________________________________
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.
Received on Fri 11 Jul 2008 - 18:59:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Jul 2008 - 22:31:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive