> gregexpr(pattern = '$',"data.frame.name$variable.name")
[[1]]
[1] 30
attr(,"match.length")
[1] 0
attr(,"useBytes")
[1] TRUE
But it does not work; Note:
< pre>> nchar(“data.frame.name$variable.name”)
[1] 29
How do you find the position of $ in this string?
> gregexpr(pattern ='\$',"data.frame.name$variable.name")
[[1]]
[1] 16
attr(,"match.length")
[1] 1
attr(,"useBytes")
[1] TRUE
< p>…gave the correct answer – namely 16.
Based on the suggestion here: Find location of character in string, I tried this:
p>
> gregexpr(pattern ='$',"data.frame.name$variable.name")
[[1]]
[1] 30
attr(,"match.length")
[1] 0
attr(,"useBytes")
[1] TRUE
But it doesn’t Works; note:
> nchar("data.frame.name$variable.name")
[1] 29
You How to find the position of $ in this string?
The problem is that $ is the end of string token in regular expressions. Try this:
> gregexpr(pattern ='\$',"data.frame.name$variable.name")
[[1]]
[1] 16
attr(, "match.length")
[1] 1
attr(,"useBytes")
[1] TRUE
… gives the correct answer – that is 16 .