Uploaded by Avishkar paringe

Practical 3

advertisement
Practical 3
• Using R execute the statistical function: mean ,
median, mode, quartiles, range, inter quartile range
histogram.
• Mean:Q.find the median of 12,7,3,4,2,18,54,21,8,5
#create vector
x<-c(12,7,3,4,2,18,54,21,8,5)
> #find the mean
> result.mean<-median(x)
> print(result.mean)
Output:-
• Applying trim option mean
>x<-c(12,4,5,20,22,5,7)
> result.meran<-mean(x,trim=0.3)
> print(result.meran)
Output:-
• Median:Q - find the median of 12,7,3,4.2,18,2,5-21,8,-5
#create vector
>x<-c(12,7,3,4.2,2,18,54,-21,8,-5)
> #find the median
> median.result<-median(x)
> print(median.result)
Output:-
• Mode:Q.find the mode of 2,1,2,3,1,2,3,4,1,5,5,3,2,2,3
# Create the function.
> getmode <- function(v) {
> uniqv <- unique(v)
>uniqv[which.max(tabulate(match(v, uniqv)))]
>}
> # Create the vector with numbers.
> v <- c(2,1,2,3,1,2,3,4,1,5,5,3,2,3)
> # Calculate the mode using the user function.
> result <- getmode(v)
> print(result)
Output:-
Q.find the mode of charecters.
> # Create the vector with characters.
> charv <- c("o","it","the","it","it")
> # Calculate the mode using the user function.
> result <- getmode(charv)
> print(result)
Output:-
Range:Q.find the range of the eruption duration in the data set
faithful.
>duration = faithful $eruptions
> max(duration)-min(duration)
Output:-
Download