Calculating mean and standard deviation in R in one column depending on factors in other columns -


i calculate mean , standard deviation data in "skada" column depending in 3 other columns. table looks this: enter image description here

the "geografi" column have categorical variables: sv, nv, m, so, sv

the "gradering" column have categorical variables: 1, 2

the "plats" column have categorical variables: 20m, kant

in other words, means have mean , standard deviation sv,1,20m; sv,2,20m; sv,1,kant; sv,2,kant; nv,1,20m,...... , forth. have tips on how easily?

cheers!

you can use data.table:

library(data.table)   setdt(data)[, list(skada_mean = mean(skada), skada_sd = sd(skada)),                   = c("geografi", "gardering", "plats")] 

or dyplr:

library(dplyr)  data %>%      group_by(geografi, gardering, plats) %>%      summarise(skada_mean = mean(value), skada_sd = sd(value)) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -