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:
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
Post a Comment