How do I combine the tapply command with 'not in' logic?
Objective: Obtain the median sepal length for each species.
tapply(iris$Sepal.Length, iris$Species, median)
Constraint: Remove entries for which there is a petal width of 1.3 and 1.5.
!iris$Petal.Width %in% c('1.3', '1.5')
Attempt:
tapply(iris$Sepal.Length, iris$Species, median[!iris$Petal.Width %in% c('1.3', '1.5')])
Result: error message 'object of type 'closure' is not subsettable'.
---
My attempt here with the iris dataset is a stand-in demo for my own dataset. I have attempted the same approach with my own dataset and received the same error message. I imagine something is wrong with my syntax. What is it?
median[!iris$Petal.Width %in% c('1.3', '1.5')]
you are subsetting a function here. This yields in an error. You cant use [ ] on functions. – Uniformize