On Tue, Jul 26, 2011 at 10:12 AM, Ista Zahn <iz...@psych.rochester.edu>
wrote:
> OK, easy enough:
>
> dat.tmp <- data.frame(id, month, value)
> my.plot <- function(dat) {print(dat[, c("id", "value")])}
> by(dat.tmp, id, my.plot)

Excellent. The output of that last line is:

* id value
1  1    10
2  1    12
3  1    11
4  1    14
5  1    16
 id value
6  2    12
7  2    10
8  2     8
  id value
9   3    14
10  3    11
11  3    15
id: 1
 id value
1  1    10
2  1    12
3  1    11
4  1    14
5  1    16
------------------------------------------------------------
id: 2
 id value
6  2    12
7  2    10
8  2     8
------------------------------------------------------------
id: 3
  id value
9   3    14
10  3    11
11  3    15*

I want the second part (separated by IDs), and not the first part. I tried
this:

> by(dat.tmp, id, my.plot) -> output

Output has exactly what I want. However, the first part is still printed on
the screen. How can I prohibit the first part to be printed?

> Why? What do you have against loops?

Nothing personal! I just see this notion of avoiding loops and using R-style
functions over and over in my readings and my first R instructor also
mentioned R is a very powerful language as long as we avoid loops. I don't
have a thorough knowledge of why loops are not as efficient as vector-based
solutions, but I trust what I've heard and read.

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to