Skip to content

If Loop I Think

1 message · Jim Lemon

#
Notice that I used the argument stringsAsFactors=FALSE to do this when
reading in.
What I did was to change Rn columns to 1 if there were any characters
in the corresponding Runnerxxx column and 0 otherwise. The "nchar"
function returns the number of characters in a string. If I apply ">0"
to it, I get TRUE(1) if nchar returns a number larger than zero and
FALSE (0) otherwise. By using the result of this operation as the
first argument in the call to "ifelse", I can set the values of the Rn
columns one by one. It is possible to do all three in one call with an
appropriate  function:

whos_on_first<-function(x)
 return(as.numeric(nchar(x) > 0))
phdf[,6:8]<-sapply(phdf[,3:5],whos_on_first)

Jiim
On Wed, Oct 23, 2019 at 11:20 AM Phillip Heinrich <herd_dog at cox.net> wrote: