Re: [R] test the return from grep or agrep

2014-03-02 Thread Prof Brian Ripley
On 01/03/2014 23:32, Hui Du wrote: Hi All, My sample code looks like options(stringsAsFactors = FALSE); clean = function(x) { loc = agrep("ABC", x$name); x[loc,]$new_name <- "NEW"; x; } name = c("12", "dad", "dfd"); y = data.frame(name = as.character(name), idx = 1:3); y$new_nam

[R] test the return from grep or agrep

2014-03-01 Thread Hui Du
Hi All, My sample code looks like options(stringsAsFactors = FALSE); clean = function(x) { loc = agrep("ABC", x$name); x[loc,]$new_name <- "NEW"; x; } name = c("12", "dad", "dfd"); y = data.frame(name = as.character(name), idx = 1:3); y$new_name = y$name; z <- clean(y) The snippet