[R] Question about Factors

Don MacQueen macq at llnl.gov
Mon Sep 14 17:50:28 CEST 2009


The suggestions from others to use lattice's xyplot, or ggplot2 are good.

If you want an explicit loop you can do something like:

for ( nm in unique(mydat$Name) ) {
   with( subset( mydf, Name==nm) ,
      {
       plot(Time, Value, title=nm)
       readline('CR to continue ')
      }
   )
}


At 5:19 PM -0700 9/13/09, Chris Li wrote:
>Hi all,
>
>I am new to R and I have got a question in regards to factors.
>
>Say I have a simple dataset like the following:
>
>Name   Time     Value
>a         1:00     1.25
>a         2:00     1.26
>b         1:00     1.29
>b         2:00     1.28
>c         1:00     1.21
>c         1:30     1.20
>c         2:00     1.23
>
>I want to write a script that automatically plot value against time for a, b
>and c. Because I have got more than 1 datasets, therefore the name of the
>next dataset may consist d, e, h and g. So I will need a script that can
>detect the changes in Name automatically.
>
>Thank you very much for your time.
>
>Chris
>--
>View this message in context: 
>http://*www.*nabble.com/Question-about-Factors-tp25428665p25428665.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at 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.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062




More information about the R-help mailing list