[R] by & tapply
y0004379 at tu-bs.de
Wed Aug 30 11:22:44 CEST 2000
it is hard to answer without a example, which can be
reproduced. I'll try:
I think you have a data with a like:
xx <- data.frame(y=rnorm(100),
##and do a:
##if you look at values:
##you see that by passes a vector to plot.
##you can do a
xn <- codes(x1)
##or you use a loop:
for( i in unique(codes(x1))) plot.default(x2 [codes(x1)== i]
, y[codes(x1)==i ]
##of course there might be ways to use tapply, lapply etc.
If you want to know why plot.default is nessary to avoid the boxpots, read
the documentation of R "R-intro" part 3.4 "The class of an object" and
On Tue, 29 Aug 2000, Steve Arthur wrote:
> I have been using the function 'by' in such a manner:
> by(LogMetric, list(Loci.Number=Loci.Number, Code.Flag=Code.Flag), plot)
> to produce a single R Graphics: Device with 14 different plots on it as
> described above in my 'by' statement. Thank you for helping me thus far.
> A similar command using 'tapply' can be written as well.
> My problems being:
> 1) Although several LogMetric values may be plotted against several of
> the same factors (x-value), they are not listed under the same x-value,
> but as separate points (which does not make sense for an x-y plot). When
> I just use the plot(x,f) I get boxplots which I don't want, I want to see
> the individual y-points above a particular x-value.
> 2) Using 'tapply' or 'by', can non-numeric x-labels be generate for the
> plots, of which the factors are R factors. I don't understand why the
> numeric values are appearing in the first place.
> 3) Is there another, simpler, way to subset data and make intelligible
> plots with R? This industrial strength stuff takes two seconds in SAS (I
> am not implying anything by that statement). I would think this would be
> a very common statistical task to complete.
> PS Addition to hopefully receiving good "by" and "tapply" examples from
> 1) Can the 'for' statement 'for (var in seq) expr' use factors as
> agruements? The example in manual says 'for(i in 1:5)'. I would want to
> do something like 'for(i in Loci.Number)' w/o being able to specify a
> general range in advance I am lost. Am I lost? Unfortunately, CRAN
> rejects my two searches for 'by' and 'for'?
> 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
P.Malewski, Maschplatz 8, 38114 Braunschweig, Tel.: 0531 500965,
At work: (MH-Hannover): 0511 532 3194 / Fax: 0511 532 3190,
P.Malewski at tu-bs.de, peter.malewski at gmx.de, malewski.peter at mh-hannover.de.
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