Friday 23 August 2013

Shortcut for if else

Shortcut for if else

What is the shortest way to express the folowing decission rule
df<-data.frame(a=LETTERS[1:5],b=1:5)
index<-df[,"a"]=="F"
if(any(index)){
df$new<-"A"
}else{
df$new<-"B"
}

No comments:

Post a Comment