본문 바로가기
반응형

R71

(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.
(R) Sorting vector, data frame / sort(), order(),xtfrm > x = c(1:3,9,7,4)> sort(x)[1] 1 2 3 4 7 9> sort(x, decreasing = TRUE)[1] 9 7 4 3 2 1 > head(Animals) body brainMountain beaver 1.35 8.1Cow 465.00 423.0Grey wolf 36.33 119.5Goat 27.66 115.0Guinea pig 1.04 5.5Dipliodocus 11700.00 50.0 > ani order1=order(row.names(ani)) > order1 [1] 15 7 26 11 24 2 6 8 12 4 19 13 3 5 9 14 23 18 27 1 20 28 10 21 25 17[27] 22 16 > ani_2 ani_2 body brainAfrican eleph.. 2020. 11. 8.
(R) ANOVA TEST ANOVA TEST is abbreviation of 'analysis of variance.' I can explain it efficiently comparing with T-test. We use T-test in decision whether to accept the alternative hypothesis or not. Normally, we use T-test dealing with two groups which becomes the subject of comparison. When the number of groups for comparisons is more than 2, the type 1 error(significance level) becomes larger in multiple. S.. 2020. 11. 7.
(R) reorganize data frames - stack, unstack, reshape function We sometimes need to reorganize data frames in a new form according to certain needs for making functions or statistical calculations. > dat1=data.frame(A=runif(20,0,0.7),B=runif(20,0,0.9),C=runif(20,0.8))> dat1 A B C1 0.60730714 0.34485044 0.80838562 0.43592037 0.68032657 0.85261013 0.41984612 0.89238618 0.94683204 0.48211414 0.06180126 0.94203135 0.62057361 0.44256735 0.96726916 0.65831211 0.2.. 2020. 11. 7.
반응형