notin - Combining tapply and 'not in' logic, using R -


how combine tapply command 'not in' logic?

objective: obtain median sepal length each species.

tapply(iris$sepal.length, iris$species, median) 

constraint: remove entries there petal width of 1.3 , 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' not subsettable'.

---

my attempt here iris dataset stand-in demo own dataset. have attempted same approach own dataset , received same error message. imagine wrong syntax. it?

try

with(iris[!iris$petal.width %in% c('1.3', '1.5'),], tapply(sepal.length, species, median)) # setosa versicolor  virginica  #    5.0        5.8        6.5  

the idea here operate on subset-ted data in first place.

your line didn't work because fun argument should applied on x (sepal.length in case) rather on whole data set.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -