Summarizing and Processing Data
In R, you can easily obtain summary statistics of the data. Below are some of the examples.
## [1] 35 23 14 17 23 35 27 33 32 31 34 27 51 36 39 45 31 40 25 32
## [1] 31.5
## [1] 32
## [1] 78.36842
## [1] 8.852594
## [1] 14 51
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 14.00 26.50 32.00 31.50 35.25 51.00
## [1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2
##
## 1 2
## 10 10
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.0 1.0 1.5 1.5 2.0 2.0
Summary statistics of ‘score’ variable for each category of ‘method’ can be also produced by using tapply() function. tapply() requires you to type in a vector, an index (i.e., factor(s)), and a function to apply. Note that the vector and factor must have the same length.
# tapply(vector object, index, function)
tapply(data$score, as.factor(data$method), mean) # returns the mean of 'score' for each 'method'
## 1 2
## 27 36
To write the codes more efficiently, you can use with() function. For example:
## [1] 31.5
## 1 2
## 27 36