[R] Program advice

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Jan 18 12:33:44 CET 1999


John Logsdon <j.logsdon at lancaster.ac.uk> writes:

> Example data:
> Item    Size  Year
> 1       0     1980
> 1       10    1981
> 1       14    1982
> 1       20    1983
> 1       25    1984
> 1       30    1985
> 2       0     1980
> 2       5     1981
> 2       6     1982
> 2       8     1984
> 3       0     1984
> 3       2     1985
> 4       0     1980
> 4       20    1981
> 4       30    1982
> 4       30    1984
> 4       35    1985
> 
> This should produce 4 jagged lines on a plot, some shorter than others.
> 
> So far, I can see no simple equivalent of the $GRA instruction with the
> factors but presumably the trick is to fill up a matrix with the data in a
> rather ugly loop storing the row number and incrementing on a change in
> Item.  Ensure that the matrix is NA-filled first and then use matplot to
> do the graph.

Hmm... Best I could think of till now was:

 dfr<-read.table("/tmp/data",header=T)
 evalq(plot(Year,Size,type='n'),dfr)
 invisible(lapply(split(dfr,dfr$Item), 
	function(d)evalq(lines(Year,Size,lty=Item),d)))

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list