(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.
(R) functions for tables/ table(), ftable(),addmargins(), prop.table(), margin.table()
table function is generally used for the frequency of each elements in variables. *table of a variable (a variable: gender)> x = c(rep("M", 3), rep("F", 2), rep(NA, 3))> x[1] "M" "M" "M" "F" "F" NA NA NA > table(x)xF M 2 3 Without 'exclude=NULL' we reject missing values automatically. If you want to add NA in the table, you can add 'exclude=NULL' Include NA in table Not include NA in table >tabl..
2020. 11. 8.