I have data that looks like this:
> x
Date Obs
1/1/2012 4
1/2/2012 40
1/3/2012 50
And a function like this:
myDat <- function(x, summarize)
{
if (summarize == T)
{
print(summary(x))
}
if (missing(summarize) | summarize == F)
{
print(x)
}
}
when I try to run it as:
myDat(x)
I get this error:
Error in summarize == T : 'summarize' is missing
what am I doing here wrong?
Use defaults for your
summarizeargument and your function simplifies to one line:Try it: