Skip to content
Back to formatted view

Raw Message

Message-ID: <499D6C24.2010101@gmail.com>
Date: 2009-02-19T14:26:44Z
From: Stefan Uhmann
Subject: code patterns in vector

Dear List,

I have this column/vector:

vec <- c("function", "missing", "string")

and want to compute a second column/vector:
- value if the pattern "unc" is found: 1
- value if the pattern "iss" is found: 2
- value if none of the patterns is found: 0

This should be the result:
 > vec2
[1] 1 2 0

Any help? Tried it with grep, but the output is not as long as vec, so 
I'm lost a bit here.

Thanks,
Stefan