How about:

for(i in c(16,24,32,40))
{
par(mfrow=c(2,4))
for(j in c(i:(i+7))
 {
hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100))
 }
png("histogram.png")
dev.off()
}



----------------------------------------------


My contact information:
Tal Galili
E-mail: Tal.Galili@gmail.com
Phone number: 972-52-7275845
FaceBook: Tal Galili
My Blogs:
http://www.talgalili.com (Web and general, Hebrew)
http://www.biostatistics.co.il (Statistics, Hebrew)
http://www.r-statistics.com/ (Statistics,R, English)




On Tue, Nov 17, 2009 at 5:38 AM, ychu066 <ychu066@aucklanduni.ac.nz> wrote:

>
> I have the following codes but can anyone make it shorter i.e making these
> FOR loop into one loop ...
> thanks...
>
> par(mfrow=c(2,4))
> for(i in 16:23){
>
> hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100))
> }
> png("histogram.png")
> dev.off()
>
> par(mfrow=c(2,4))
> for(i in 24:31){
>
> hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100))
> }
> png("histogram.png")
> dev.off()
>
> par(mfrow=c(2,4))
> for(i in 32:39){
>
> hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100))
> }
> png("histogram.png")
> dev.off()
>
> par(mfrow=c(2,4))
> for(i in 40:47){
>
> hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100))
> }
> png("histogram.png")
> dev.off()
>
>
> --
> View this message in context:
> http://old.nabble.com/Plotting-graphs-using-FOR-loop-tp26383926p26383926.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]


