R "object x not found error" in calling self-defined function
I used the following function to remove the lowest-ranked data (marking
them as NA):
RemoveOutlier<- function(x, pctl){
qnt <- quantile(x, probs = pctl)
y <- x
y[x <= qnt] <- NA
y
} # remove the bottom pctl% data
For example, RemoveOutlier(x=seq(1,10,1), 0.1) will remove the bottom 10%
of data.
Then I tried to apply this function to iris$Petal.Width by Species,
generating a new column Petal.Width.Rm:
iris$Petal.Width.Rm <- with(iris, ave(Petal.Width, Species, FUN =
RemoveOutlier(x, 0.1)))
But I had the error object 'x' not found. What's the problem here?
Tuesday, August 13, 2013
R "object x not found error" in calling self-defined function
Posted on 7:39 AM by Unknown
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment