Advertisement
crhunter

05

Sep 19th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.45 KB | None | 0 0
  1. #importing CSV
  2. setwd("C:\\Users\\cr\\Desktop\\lab5")
  3. data<-read.table("Data.txt",header = TRUE,sep = ",")
  4. #givinga values to the colomns
  5. names(data)<-c("X1","X2")
  6. attach(data)
  7. fix(data)
  8. #drawing the histogram
  9. hist(X2,main = "histogram for share holders")
  10. #draw histogram using 7 classes
  11. histogram<-hist(X2,main = "histogram for share holders",breaks = seq(130,270,length=8))
  12.  
  13. #frequency distribution
  14. breaks<-round(histogram$breaks)
  15. breaks
  16.  
  17. freq<-histogram$counts
  18. freq
  19.  
  20. mids<-histogram$mids
  21. mids
  22.  
  23. classes<-c()
  24. for(i in 1:length(breaks)-1){
  25.   classes[i]<-paste("[",breaks[i],",",breaks[i=1],")")
  26. }
  27.  
  28. #colomn bind- can be used to combine two data frames with the s
  29.  
  30. cbind(classes=classes,frequency=freq)
  31.  
  32. #end frequncy
  33.  
  34. #Portray the distribution in the form of a frequency polygon.
  35. #add frequency polygon to the same plot
  36. lines(mids,freq)
  37. #draw frequncy polygon in a new plot.
  38. plot(mids,freq,type = 'p',main = "Frequency polygon for shareholders",
  39.      xlab = "shareholders", ylab = "Frequncy",
  40.      ylim = c(0,max(freq)))
  41. #q5)
  42. #Portray the distribution in a less-than cumulative frequency polygon.
  43. cum.freq<-cumsum(freq)
  44. new<-c()
  45. for(i in 1:length(breaks)){
  46.   if(i==1){
  47.     new[i]=0
  48.   }else{
  49.     new[i]=cum.freq[i-1]
  50.   }
  51. }
  52. cbind(upper=breaks,cumFreq=new)
  53. plot(breaks,new,type = 'l',main = "frequency polygon for share holders",
  54.      xlab = "ahareholderes",ylab = "Cumlative frequncy",
  55.      ylim = c(0,max(cum.freq)))
  56.   }
  57.   }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement