Skip to content
Prev 320609 / 398506 Next

From a vector with characters to binary information

On 29-03-2013, at 20:01, Hermann Norpois <hnorpois at gmail.com> wrote:

            
First of all read the help page for sapply (and other apply's) in particular the part describing argument USE.NAMES.

You don't need to use ifelse: a simple if/else will do. x is a scalar in your function and ifelse is overkill. So you also don't need to use |.

So

scoref <- sapply (scm, function (x) if (x == "keine" || x==" ")  0 else 1, USE.NAMES=FALSE)

or

scoref <- sapply (scm, function (x) 1-(x == "keine"||x==" "), USE.NAMES=FALSE)

Berend