RE: [R] how to loop through names ?

About this list Date view Thread view Subject view Author view Attachment view

From: Adaikalavan Ramasamy (ramasamy@cancer.org.uk)
Date: Tue 23 Mar 2004 - 04:12:58 EST


Message-id: <ODEPICOHNDBJEHIFCIMPKEMBCBAA.ramasamy@cancer.org.uk>

Try plot( sales[ 13:24, "serial" ], sales[ 13:24, i ], xlab="Month No",
ylab="No/month")

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch]On Behalf Of Pete Phillips
> Sent: 06 March 2004 09:53
> To: r-help@stat.math.ethz.ch
> Subject: [R] how to loop through names ?
>
>
>
> Hi
>
> I'm sure I'm missing something very straighforward here :-(
>
> I have a data set 'sales' as follows:
> ==========================================
> # read in the sales data
> sales<-read.table("sales.dat",header=TRUE);
> #generate a serial field
> sales$serial=c(1:24)
>
> sales
>
> an l ml ne ni total serial
> 1 43 25 35 51 17 69 1
> 2 38 18 47 94 3 99 2
> .......
> 24 58 13 41 95 4 1 24
> ===========================================
>
> (extra rows and columns deleted).
>
> I wish to produce a postscript plot file for each column plotted vs the
> serial column, using either the 1st to 12th row or the 13th to 24th
> rows, where the filename consists of the column name with '.ps' added.
>
> This the code I have so far:
>
> ============================================
> for (i in 1:(length(names(sales))-1)) {
>
> fname <- paste(names(sales)[[i]],".ps",sep="")
>
> postscript(file=fname)
>
> plot(
> sales$serial[13:24],
> sales[names(sales)[[i]]][13:24],
> xlab="Month No", ylab="No/month")
> dev.off()
>
> }
> ==============================================
>
> The filename generation works (yay!), but I think I have missed
> something very basic here as that plot line seems too complex (and
> doesn't work!).
>
> Any ideas please ?
>
> Pete
> --
> Pete Phillips, Deputy Director, | http://www.smtl.co.uk/
> Surgical Materials Testing Lab, | http://www.worldwidewounds.com/
> Princess of Wales Hospital, S Wales | http://www.dressings.org/
> Tel/Fax: +44 1656-752820/30 | pete@smtl.co.uk
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Fri 23 Apr 2004 - 18:36:39 EST