[R] using "for" loop

Renaud Lancelot renaud.lancelot at cirad.fr
Fri Aug 5 11:12:48 CEST 2005


alessandro carletti a écrit :
> Hi everybody,
> how can I create a loop for plotting parameters for
> each level of a variable, for example:
> 
> NAME   temperature  depth
> aaa      23           -1
> aaa      22           -2
> aaa      24           -1
> bbb      23           -4
> bbb      23           -1 
> aaa      22           -1
> bbb      22            0
> 
> I mean, I would like R to plot temperature vs depth
> for aaa, then another plot for bbb, and so on.
> 
> Is it for loop ok?
> Thanks

Package lattice is your friend. Using your example:

Data <- read.table(file = "clipboard", header = TRUE)
library(lattice)
xyplot(temperature ~ depth | NAME, data = Data)

Best,

Renaud

-- 
Dr Renaud Lancelot, vétérinaire
Projet FSP régional épidémiologie vétérinaire
C/0 Ambassade de France - SCAC
BP 834 Antananarivo 101 - Madagascar

e-mail: renaud.lancelot at cirad.fr
tel.:   +261 32 40 165 53 (cell)
         +261 20 22 665 36 ext. 225 (work)
         +261 20 22 494 37 (home)




More information about the R-help mailing list