r - Specific substring detection into a large string -
i have kind of data column in character matrix. apply column v1 grep function detect "ok", "error" or "noise" strings, , save them new column.
from img 1
"";"v1" "img1";"19293.jpg : h344.8º : ok" "img1";"19293.jpg : 9.6kt : ok" "img1";"19293.jpg : 44º31.449h'n : error" "img1";"19293.jpg : 2º31.238'w : ok" "img2";"19294.jpg : h344.8º : ok" "img2";"19294.jpg : 9.6kt : ok" "img2";"19294.jpg : 44º31.449h'n : noise" "img2";"19294.jpg : 2º31.238'w : ok" "img3";"19295.jpg : h344.8º : ok" "img3";"19295.jpg : 9.6kt : ok" "img3";"19295.jpg : 44º31.449h'n : ok" "img3";"19295.jpg : 2º31.238'w : ok" ...
until img n
thanks!
read in data file with
x <- read.table( "data.dat", sep = ";", header = true ) add column last word of x$v1
library( stringr ) x$extr <- word( x[,2], -1 ) x x v1 extr 1 img1 19293.jpg : h344.8º : ok ok 2 img1 19293.jpg : 9.6kt : ok ok 3 img1 19293.jpg : 44º31.449h'n : error error 4 img1 19293.jpg : 2º31.238'w : ok ok 5 img2 19294.jpg : h344.8º : ok ok 6 img2 19294.jpg : 9.6kt : ok ok 7 img2 19294.jpg : 44º31.449h'n : noise noise 8 img2 19294.jpg : 2º31.238'w : ok ok 9 img3 19295.jpg : h344.8º : ok ok 10 img3 19295.jpg : 9.6kt : ok ok 11 img3 19295.jpg : 44º31.449h'n : ok ok 12 img3 19295.jpg : 2º31.238'w : ok ok
Comments
Post a Comment