I'm writing a function that needs an optional variable. If the variable is
given, then a subset must be made using that variable, but if the variable
is not given the subset must be done using all the values for that variable
(ignoring that variable).

Something like this:

*band <- function(file, fruit = "apple", optional=TRUE) {*

*data <- read.csv(file)*

*a <- nrow(subset(data, 'Column 1' == fruit & 'Column 2'=="hot" & 'Column 3'==
optional))*

*b <- nrow(subset(data,'Column 1' == fruit & 'Column 2'=="cold" & 'Column 3'==
optional)) *

*z <- a+b*

* print(z)*

* }*

What I need is that the function *band("file","orange")*,  subset the data
frame using all possible values for Column 3 but is not doing it.

All ideas are welcome.

Thanks.


David Mora

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to