This process lies in finding statistics which consist of more than one variable, grouped or crossed by factors. The table must be organized by columns between variables and factors.
tapply.stat(y, x, stat = "mean")
y | data.frame variables |
---|---|
x | data.frame factors |
stat | Method |
Statistics of quantitative variables by categorical variables.
library(agricolae) # case of 1 single factor data(sweetpotato) tapply.stat(sweetpotato[,2],sweetpotato[,1],mean)#> sweetpotato[, 1] sweetpotato[, 2] #> 1 cc 24.40000 #> 2 fc 12.86667 #> 3 ff 36.33333 #> 4 oo 36.90000#> virus yield #> 1 cc 3.609709 #> 2 fc 2.159475 #> 3 ff 7.333030 #> 4 oo 4.300000#> virus yield #> 1 cc 6.8 #> 2 fc 4.3 #> 3 ff 13.8 #> 4 oo 8.3#> virus yield #> 1 cc 3.40 #> 2 fc 2.15 #> 3 ff 6.90 #> 4 oo 4.15#> site lineage epoca yield #> 1 Lima 1 1 12.500000 #> 2 Lima 1 2 18.666667 #> 3 Lima 2 1 12.333333 #> 4 Lima 2 2 17.333333 #> 5 Lima 3 1 11.000000 #> 6 Lima 3 2 13.333333 #> 7 Lima 4 1 8.833333 #> 8 Lima 4 2 11.500000 #> 9 Pisco 1 1 14.833333 #> 10 Pisco 1 2 20.166667 #> 11 Pisco 2 1 17.000000 #> 12 Pisco 2 2 21.166667 #> 13 Pisco 3 1 15.833333 #> 14 Pisco 3 2 21.166667 #> 15 Pisco 4 1 14.666667 #> 16 Pisco 4 2 20.000000#> site epoca yield #> 1 Lima 1 15 #> 2 Lima 2 26 #> 3 Pisco 1 26 #> 4 Pisco 2 27# Height of pijuayo data(growth) with(growth,tapply.stat(height, growth[,2:1], function(x) mean(x,na.rm=TRUE)))#> slime place height #> 1 5 L1 8.433333 #> 2 6 L1 10.950000 #> 3 6 L2 11.350000 #> 4 7 L1 9.375000 #> 5 7 L2 12.000000 #> 6 9 L1 10.500000 #> 7 9 L2 12.400000 #> 8 10 L1 12.200000 #> 9 10 L2 10.600000 #> 10 11 L2 11.433333 #> 11 12 L2 12.500000 #> 12 13 L2 11.500000 #> 13 14 L2 11.500000 #> 14 15 L2 11.900000 #> 15 17 L1 11.233333 #> 16 18 L1 10.100000