(R) lapply, sapply, mapply/ two-sample t-test using mapply function
lapply function always returns the result of function as a list from a list. sapply function always returns the result of functions as a vector from a list. > list_1=list(x=rnorm(5,0,1),y=runif(3,5,10))> list_1$x[1] -0.1718824 -0.1953697 -0.3611449 1.1755966 -1.0458594 $y[1] 7.881664 9.084847 9.950752 > list_2 = list(x = rnorm(10,0,1), y = c(rnorm(5,3,8), NA)) > list_2$x [1] 1.76547974 -0.748861..
2020. 11. 17.
(R) apply function on matrix and data frame
There are some functions provided by R to calculate statistics for rows or columns for matrix. columns, rowSums, colMeans, rowMeans are the things. > x = matrix(runif(20,min=2,max=35), 3) > x [,1] [,2] [,3] [,4] [,5] [,6][1,] 25.49332 29.93656 8.329258 9.427876 6.314251 11.469574[2,] 32.90328 25.86397 25.692699 23.865729 32.419499 33.890851[3,] 17.61071 20.22315 33.823737 18.290469 4.744376 6.37..
2020. 11. 15.