Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #importing CSV
- setwd("C:\\Users\\cr\\Desktop\\lab5")
- data<-read.table("Data.txt",header = TRUE,sep = ",")
- #givinga values to the colomns
- names(data)<-c("X1","X2")
- attach(data)
- fix(data)
- #drawing the histogram
- hist(X2,main = "histogram for share holders")
- #draw histogram using 7 classes
- histogram<-hist(X2,main = "histogram for share holders",breaks = seq(130,270,length=8))
- #frequency distribution
- breaks<-round(histogram$breaks)
- breaks
- freq<-histogram$counts
- freq
- mids<-histogram$mids
- mids
- classes<-c()
- for(i in 1:length(breaks)-1){
- classes[i]<-paste("[",breaks[i],",",breaks[i=1],")")
- }
- #colomn bind- can be used to combine two data frames with the s
- cbind(classes=classes,frequency=freq)
- #end frequncy
- #Portray the distribution in the form of a frequency polygon.
- #add frequency polygon to the same plot
- lines(mids,freq)
- #draw frequncy polygon in a new plot.
- plot(mids,freq,type = 'p',main = "Frequency polygon for shareholders",
- xlab = "shareholders", ylab = "Frequncy",
- ylim = c(0,max(freq)))
- #q5)
- #Portray the distribution in a less-than cumulative frequency polygon.
- cum.freq<-cumsum(freq)
- new<-c()
- for(i in 1:length(breaks)){
- if(i==1){
- new[i]=0
- }else{
- new[i]=cum.freq[i-1]
- }
- }
- cbind(upper=breaks,cumFreq=new)
- plot(breaks,new,type = 'l',main = "frequency polygon for share holders",
- xlab = "ahareholderes",ylab = "Cumlative frequncy",
- ylim = c(0,max(cum.freq)))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement