Skip to content

histogram

1 message · arun

#
HI Elisa,
You could use ?cut()


vec1<-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45)
label1<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i) paste(i[1],"<x<=",i[2],sep="")))

?Count1<-as.data.frame(table(cut(vec1,breaks=seq(0,50,5),labels=label1)))


?Count1
#?????? Var1 Freq
#1??? 0<x<=5??? 5
#2?? 5<x<=10??? 5
#3? 10<x<=15??? 5
#4? 15<x<=20??? 5
#5? 20<x<=25??? 5
#6? 25<x<=30??? 5
#7? 30<x<=35??? 5
#8? 35<x<=40??? 5
#9? 40<x<=45??? 5
#10 45<x<=50??? 5
hist(vec1,breaks=seq(0,50,5),freq=T)

?hist(vec1,breaks=seq(0,50,5),prob=TRUE)
?lines(density(vec1))

label2<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(55,by=50,length.out=10),function(x) x),SIMPLIFY=FALSE),function(i) paste(i[1],"<x<=",i[2],sep="")))
?count2<-as.data.frame(table(cut(vec1,breaks=c(0,55,100,145,190,235,280,325,370,415,460),labels=label2)))
count2
#??????? Var1 Freq
#1??? 0<x<=55?? 50
#2?? 5<x<=105??? 0
#3? 10<x<=155??? 0
#4? 15<x<=205??? 0
#5? 20<x<=255??? 0
#6? 25<x<=305??? 0
#7? 30<x<=355??? 0
#8? 35<x<=405??? 0
#9? 40<x<=455??? 0
#10 45<x<=505??? 0

hist(vec1,breaks=c(0,55,100,145,190,235,280,325,370,415,460))
?hist(vec1,breaks=c(0,55,100,145,190,235,280,325,370,415,460),prob=TRUE)
?lines(density(vec1))

A.K.