ave Function in R (Example) | Get Group Averages Over Factor Levels | Calculate Mean & Add to Data
Автор: Statistics Globe
Загружено: 2022-11-17
Просмотров: 1139
How to calculate averages using the ave function in the R programming language. More details: https://statisticsglobe.com/ave-funct...
R code of this video:
data <- data.frame(value = c(3, 1, 5, 5, 6, 2, 8, 1), # Create example data frame
group = rep(letters[1:4], each = 2))
data # Print example data frame
mean_all <- mean(data$value) # Apply mean function
mean_all # Result of mean function
ave_all <- ave(data$value, # Apply ave function
FUN = mean)
ave_all # Result of ave function
ave_group <- ave(data$value, # Apply ave function by group
data$group,
FUN = mean)
ave_group # Print average by group
data_new <- data.frame(data, # Combine data and ave output
ave_group)
data_new # Print new data frame
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – R Programming Group for Discussions & Questions: / statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: / statisticsglobepython
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – R Programming Group for Discussions & Questions: / 12555223
LinkedIn – Python Programming Group for Discussions & Questions: / 12673534
Twitter: / joachimschork
Music by bensound.com
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: