[R] help wrapping findInterval into a function

Steve E. searl at vt.edu
Tue Dec 6 23:53:51 CET 2011


Bill (and David),

Thank you very much for taking the time to respond to my query.

You were right, I was creating and calling the function exactly as you had
predicted.  I revised the structure based on your suggestion.  It runs but
the output is an array of the flags that are not attached to the data frame,
not a new column in the data frame as was my intention.

So, the new configuration I tried was like this (where DataFrame is not a
real data frame but just the word "DataFrame"):

WQFlags <- function(DataFrame) {DataFrame$CalciumFlag <- with(DataFrame,
ifelse(variable == "CaD_ICP", (dataqualifier <- c("Y", 'Q', "", "A")
[findInterval(DataFrame$value, c(-Inf, 0.027, 0.1, 100, Inf))]),""))
}

I called it using:

WaterQualityData <- WQFlags(WaterQualityData)

Again, the output is simply an array of the flags, unattached to a data
frame.  Can you suggest a way to modify this to make it work as desired, or,
in the worst case, can I attach the resulting array of flag values?


Thank you again!

--
View this message in context: http://r.789695.n4.nabble.com/help-wrapping-findInterval-into-a-function-tp4165464p4166826.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list