[R] string problems ( grep and regepxr)
MMarques Power
mmarques at inescporto.pt
Wed Mar 24 12:51:34 CET 2004
Recently working with strings and data
I have found a small problem.
Windows XP
R 1.8.1
Reading data from a "txt file" with readLine.
finding a specific line with "grep" command, all OK.
but here comes the problem...
After finding the correct line(s) i need to find a substring
inside each string.
In this case "tabs" I think it represented by "\t" in the grep command
trying to use grep in each string it only returns 1 ...
Afterwards I tried regexpr command it returns the correct position of the
substring that I am looking for but it only reports the first one.
does regexpr only returns the first one ?
Partial example:
d5 = "load0004 node0014 0.05 0.014583333"
"load0005 node0017 0.05 0.014583333"
"load0006 node0019 0.05 0.014583333"
>grep("\t",d5[1])
[1] 1
>regexpr("\t",d5[1]
[1] 9
attr(,"match.length")
[1] 1
any idea how to make regexpr return the several substrings ?
or the grep and
Am I missing anything obvious ?
THanks in advance
Marco Marques
More information about the R-help
mailing list