In R statistical analysis can be determined by using many in-built function.These in-built function takes R vector as an input along with no of argument and gives us result.
We are discussing These function i.e mean,median,trim.
- Mean:
Mean calculated by using taking sum of values and divide it with number of values .
Formula:
Mean(X,trim=0,na.rm=FALSE,…)
Description:
X: is a input vector
Trim: is used to drop some observation from both end of vector.
Na.rm: is used to remove missing value from the input vector.
> x<-c(-2,-3,-3,5,6,78,30,54)
> print(x)
[1] -2 -3 -3 5 6 78 30 54
> y<-mean(x) //We are calculating mean of x and stored into y variable.
> print(y)
Output:
[1] 20.625
- Median:
Median shows the middle value in data series.And it can calculated by using median() function.
Formula:
Median(X,na.rm=FALSE)
Description:
X:is a input vector.
Na.rm:is used to remove missing value from the input vector.
> x<-c(-2,-3,-5,5,3,8,34,24)
> print(x)
[1] -2 -3 -5 5 3 8 34 24
> y<-median(x)
> print(y)
Output:
[1] 4
- Trim:
it is used to drop observation from both end of vector.when trim argument is supplied.the value of vector get sorted.For example:when trim=0.3, it will drop some observation from both end of sorted vector.i.e supposed x is a sorted vector containing some values
x<-c(-21,3.0,4.0,5.0,6.7,8.9,9.5,16.5)
and values removed from sorted vector (-21,3.0,4.0) from the left and from the right (8.9,9.5,16.5).
> x<-c(-2,-3,-5,5,7,78,34,32)
> result<-mean(x,trim=0.3)
> print(result)
output:
[1] 10.5