How to Apply a Function to Each Element of a Matrix in R (2 Examples) | Pre- & User-Defined Command
Автор: Statistics Globe
Загружено: 2021-11-03
Просмотров: 655
Описание:
How to apply a function or command to all matrix elements in the R programming language. More details: https://statisticsglobe.com/apply-fun...
R code of this video:
mat <- matrix(1:15, nrow = 5) # Create example data
mat # Print example data
mat_new1 <- sqrt(mat) # Apply function to each element
mat_new1 # Print updated data
my_fun <- function(x) { # Create own function
x * 3 + 10
}
mat_new2 <- apply(mat, c(1, 2), my_fun) # Apply own function to each element
mat_new2 # Print updated data
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – Group for Discussions & Questions: / statisticsglobe
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – Group for Discussions & Questions: / 12555223
Twitter: / joachimschork
Music by bensound.com
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: