[R] histogram

arun smartpink111 at yahoo.com
Tue Mar 5 23:50:39 CET 2013



Hi,

I guess this is what you wanted.
Attaching a plot from a subset (lstSub)



dat1<- read.csv("rightest.csv",sep=",",header=TRUE,check.names=FALSE) 
label1=c("0-25","25-50","50-75") 
Name1<-unlist(lapply(0:123,function(i) rep(i+1,i))) 
dat1New<- dat1[,-1]
vec1<- unlist(lapply(seq_len(nrow(dat1New)),function(i) dat1New[i,][1:which(dat1New[i,]==0)-1]))
dat3<-data.frame(Name1,vec1)
dat3$Categ<-as.character(cut(dat3$vec1,breaks=seq(0,75,25),labels=label1))
source("k.txt")
lst1<- split(dat3,dat3$Name1)
#lstSub<-split(dat3,dat3$Name1)[1:4]

pdf("ElisaNew0_25.pdf")
 lapply(lst1,function(x) {indx025<-which(x$Categ=="0-25"); indx2550<-which(x$Categ=="25-50");indx5075<-which(x$Categ=="50-75"); if(length(indx025)>=1) {matplot(k[,indx025],ylim=c(0,5),type="l",col="grey",main=paste("range 0-25","line=",unique(x$Name1),sep=" "),xlab="T",ylab="Q"); lines(k[,unique(x$Name1)],type="l",col="black")} else NULL})
dev.off()

pdf("ElisaNew25_50New.pdf")
 lapply(lst1,function(x) {indx025<-which(x$Categ=="0-25"); indx2550<-which(x$Categ=="25-50");indx5075<-which(x$Categ=="50-75"); if(length(indx2550)>=1) {matplot(k[,indx2550],ylim=c(0,5),type="l",col="grey",main=paste("range 25-50","line=",unique(x$Name1),sep=" "),xlab="T",ylab="Q"); lines(k[,unique(x$Name1)],type="l",col="black")} else NULL})
dev.off()

pdf("ElisaNew50_75.pdf")
 lapply(lst1,function(x) {indx025<-which(x$Categ=="0-25"); indx2550<-which(x$Categ=="25-50");indx5075<-which(x$Categ=="50-75"); if(length(indx5075)>=1) {matplot(k[,indx5075],ylim=c(0,5),type="l",col="grey",main=paste("range 50-75","line=",unique(x$Name1),sep=" "),xlab="T",ylab="Q"); lines(k[,unique(x$Name1)],type="l",col="black")} else NULL})
dev.off()


A.K.



________________________________
From: eliza botto <eliza_botto at hotmail.com>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
Sent: Tuesday, March 5, 2013 5:04 PM
Subject: RE: histogram



Dear Arun,
Thanks for the update.
Any success with the recently asked question?
thanks


elisa


> Date: Tue, 5 Mar 2013 14:00:29 -0800
> From: smartpink111 at yahoo.com
> Subject: Re: histogram
> To: eliza_botto at hotmail.com
> CC: r-help at r-project.org
> 
> HI Elisa,
> Just noticed the order of elements in vec1:
> You have to replace `vec1`
> dat2<- as.dist(dat1[,-1],upper=F,diag=F) 
> vec1<- as.vector(dat2)
>  head(vec1)
> #[1]  5.796656 43.523023 38.193750 44.730182  6.511703  2.904954 #the order is based on columns
> 
> #with
> dat1<- read.csv("rightest.csv",sep=",",header=TRUE,check.names=FALSE) 
> label1=c("0-25","25-50","50-75")
> dat1New<- dat1[,-1]
> vec1<- unlist(lapply(seq_len(nrow(dat1New)),function(i) dat1New[i,][1:which(dat1New[i,]==0)-1]))
>  head(vec1)
> #        1         1         2         1         2         3 
> # 5.796656 43.523023 36.305633 38.193750 31.623020  5.391179  #correct order
>  dat1[1:4,1:4]
> #  St.         1         2         3
> #1   1  0.000000  5.796656 43.523023
> #2   2  5.796656  0.000000 36.305633
> #3   3 43.523023 36.305633  0.000000
> #4   4 38.193750 31.623020  5.391179
> 
> Name2<-unlist(lapply(0:123,function(i) if(length(rep(i+1,i)>=1)) paste("(",paste(rep(i+1,i)[1],seq_along(rep(i+1,i)),sep=","),")",sep="") else NULL)) 
> dat3New<- data.frame(Name2,vec1) 
> resNew<-t(aggregate(.~Name2,data=dat3New,function(x) table(cut(x,breaks=seq(0,75,25),labels=label1)))) 
> colnames(resNew)<- resNew[1,] 
> resNew1<- resNew[-1,] 
> row.names(resNew1)<-gsub("vec1.","",row.names(resNew1)) 
> Names3<-apply(resNew1,1,function(x) paste(names(which(x!=0)),collapse=",")) 
> res2<- data.frame(Frequency=apply(resNew1,1,function(x) sum(1*(x!=0))), stations=Names3,stringsAsFactors=FALSE)
> 
> A.K.
> 
> 
> 
> 
> 
> 
> ----- Original Message -----
> From: arun <smartpink111 at yahoo.com>
> To: eliza botto <eliza_botto at hotmail.com>
> Cc: 
> Sent: Tuesday, March 5, 2013 8:12 AM
> Subject: Re: histogram
> 
> Dear Elisa,
> I already sent you the solution.
> 
> 
>  Name2<-unlist(lapply(0:123,function(i) 
> if(length(rep(i+1,i)>=1)) 
> paste("(",paste(rep(i+1,i)[1],seq_along(rep(i+1,i)),sep=","),")",sep="")
> else NULL))
> dat3New<- data.frame(Name2,vec1)
> resNew<-t(aggregate(.~Name2,data=dat3New,function(x) table(cut(x,breaks=seq(0,75,25),labels=label1))))
> colnames(resNew)<- resNew[1,]
> resNew1<- resNew[-1,]
> row.names(resNew1)<-gsub("vec1.","",row.names(resNew1))
> Names3<-apply(resNew1,1,function(x) paste(names(which(x!=0)),collapse=",")) 
> res2<- data.frame(Frequency=apply(resNew1,1,function(x) sum(1*(x!=0))), stations=Names3,stringsAsFactors=FALSE)
> A.K.
> 
> ________________________________
> From: eliza botto <eliza_botto at hotmail.com>
> To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
> Sent: Tuesday, March 5, 2013 7:04 AM
> Subject: RE: histogram
> 
> 
> 
> Dear Arun,
> Extremely sorry for replying you late. i really wanted to calculate the index of dat3. It alright for me, even if the size of output is really large.
> thanks in advance
> 
> Elisa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ElisaNew25_50.pdf
Type: application/pdf
Size: 6647 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130305/48f88108/attachment.pdf>


More information about the R-help mailing list