[R] simple usage of "for"

Hans Ekbrand hans at sociologi.cjb.net
Tue Feb 19 16:07:53 CET 2008


On Tue, Feb 19, 2008 at 10:04:13AM -0500, Duncan Murdoch wrote:
> On 2/19/2008 9:24 AM, Hans Ekbrand wrote:

[...]

> > I tried the following small code snippet which I copied from the
> > "Introduction to R":
> > 
> >> for (i in 2:length(meriter)) { table(meriter[[1]], meriter[[i]]) }
> 
> Where did you find that?  I don't see anything like it.  (If there is 
> something like that, it should be fixed.)
>
> If you are referring to this snippet:
> 
>  >for (i in 1:length(yc)){
>      plot(xc [[i ]],yc [[i ]]);
>      abline(lsfit(xc [[i ]],yc [[i ]]))
> }

Yes, I copied the for construct from that snippet.

> then it has the important difference that plot() and abline() both have 
> side effects (they do plotting), whereas table() doesn't.

I see. Thanks for the explanation.

-- 
Hans Ekbrand
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080219/72af8d13/attachment.bin 


More information about the R-help mailing list