[R] histogram
arun
smartpink111 at yahoo.com
Mon Mar 4 20:56:43 CET 2013
Hi Elisa,
I am not sure about the output you wanted.
dat1<- read.csv("rightest.csv",sep=",",header=TRUE,check.names=FALSE)
dat2<- as.dist(dat1[,-1],upper=F,diag=F)
vec1<- as.vector(dat2)
label1=c("0-25","25-50","50-75")
Count1<- as.data.frame(table(cut(vec1,breaks=seq(0,75,25),labels=label1))) #Overall count
Count1
# Var1 Freq
#1 0-25 5465
#2 25-50 1992
#3 50-75 169
Name1<-unlist(lapply(0:123,function(i) rep(i+1,i)))
length(Name1)
#[1] 7626
dat3<-data.frame(Name1,vec1)
res<-t(aggregate(.~Name1,data=dat3,function(x) table(cut(x,breaks=seq(0,75,25),labels=label1))))
colnames(res)<- res[1,]
res1<- res[-1,]
row.names(res1)<-gsub("vec1.","",row.names(res1))
res1
# 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#0-25 1 0 2 0 2 3 2 1 1 1 3 1 1 3 2 3 6 3 5 2 4 8 13 21 21 23 20
#25-50 0 2 1 4 3 3 5 7 8 8 8 11 12 11 13 12 11 15 14 18 17 12 10 3 2 3 6
#50-75 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 2 0 0 2 0 1
-----------------------------------------------------------------------------------------------------
A.K.
________________________________
Fr
istogram
Dear Arun,
i have a distance matrix as attached in excel file with this email. You can read the data via R and
after reading the data i want you to extract the lower part of distance matrix by
as.dist(x, upper=F, diag=F). You will see that there
are 124 stations in my study. After that, i want to divide the data into three intervals 0-25, 25-75,
75-100. Then i want to count the number of stations falling in each interval, which will be called
"Frequency". After that i want to draw the following table
Range stations Frequency
0-25 names of station Number of stations
25-50
50-75
Finally, i want to draw histogram. i know i asked same kind of question before, but those commands are not working on distance matrix.
thankyou very very much in advance
elisa
More information about the R-help
mailing list