mean - Calculating Function from Variable 1 after Eliminating Level(s) from Variable 2 Using R -


this question asking command use given following situation:

objective: calculate mean of iris$sepal.length.

constraint: not include iris$species 'setosa'.

my work:

data(iris) levels(iris$species) 

output: setosa, versicolor, , virginica

mean(iris$sepal.length, which(iris$species != 'setosa')) 

output: error message 'incompatible dimensions'

---

this demo stand-in own dataset, want calculate function variable (such sepal.length) excludes levels second variable (such species). believe personal dataset , stand-in demo comparable.

perhaps which() not appropriate command. is?

you close, try this

mean(iris$sepal.length[which(iris$species != 'setosa')]) 

or

mean(iris$sepal.length[iris$species != 'setosa']) 

or

mean(iris[iris$species!= "setosa", "sepal.length"]) 

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? -