[R] regex - extracting 2 numbers and " from strings
David Wolfskill
r at catwhisker.org
Fri Oct 9 01:03:32 CEST 2015
On Thu, Oct 08, 2015 at 05:45:13PM -0500, Omar André Gonzáles Díaz wrote:
> Hi I have a vector of 100 elementos like this ones:
>
> a <- c("SMART TV LCD FHD 70\" LC70LE660", "LED FULL HD 58'' LE58D3140")
>
> I want to put just the (70\") and (58'') in a vector b.
>
> This is my try, but is not working:
>
> b <- grepl('^[0-9]{2}""$',a)
>
> Any hint is welcome, thanks.
> ...
Perhaps:
> a <- c("SMART TV LCD FHD 70\" LC70LE660", "LED FULL HD 58''
LE58D3140")
> b <- sub('^.* ([0-9]{2}(\'\'|")) .*$', "\\1", a)
> b
[1] "70\"" "58''"
>
Peace,
david
--
David H. Wolfskill r at catwhisker.org
Those who would murder in the name of God or prophet are blasphemous cowards.
See http://www.catwhisker.org/~david/publickey.gpg for my public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 949 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20151008/69642c95/attachment.bin>
More information about the R-help
mailing list