Description Usage Arguments Examples
Little more than a wrapper for vectorize
, allows for
duplication of SQL coalesce functionality, certain types of if-else
statements, and apply
/Reduce
combinations.
1 |
... |
an arbitrary number of |
fun |
a two argument function that returns an atomic value |
1 2 3 4 5 6 7 8 9 | coalesce(c(NA,1,2))
coalesce(c(NA,1,2),c(3,4,NA))
df<-data.frame(a=c(NA,2,3),b=c(1,2,NA))
coalesce(df$a,df$b)
# Or even just:
coalesce(df)
# Coalesce can actually use any comparison. For example, instead of non-NA
# values it could find the max in each row:
cbind(EuStockMarkets,Max=coalesce(EuStockMarkets,fun=function (x,y) if (x>y) x else y))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.