[R] Extracting first number after * in a character vector

Abhinaba Roy abhinabaroy09 at gmail.com
Mon Jan 23 13:29:55 CET 2017


Hi,

How do I extract the first number after '*' in a vector?

The vector is given below

> dput(out[1:10])
c("     1 X[0,SMITH]   *              0             0             1 ",
"     2 X[0,JOHNSON] *              0             0             1 ",
"     3 X[0,WILLIAMS]", "                    *              1             0
            1 ",
"     4 X[0,JONES]   *              0             0             1 ",
"     5 X[0,BROWN]   *              0             0             1 ",
"     6 X[0,DAVIS]   *              0             0             1 ",
"     7 X[0,MILLER]  *              0             0             1 ",
"     8 X[0,WILSON]  *              0             0             1 ",
"     9 X[0,MOORE]   *              0             0             1 "
)

I want a vector with the first number after the asterisk.

So the output would give me, a vector (0,0,1,0,0,0,0,0,0,0)

How can I do it in R?

Best,
Abhinaba

	[[alternative HTML version deleted]]



More information about the R-help mailing list