[R] Obvious reason for not looping twice?
Peter Alspach
Peter.Alspach at plantandfood.co.nz
Mon Apr 26 01:44:57 CEST 2010
Tena koe Robin
Do you get an error or warning?
It may have something to do with how == treats NA:
x <- 1:4
x[x == 1]
[1] 1
x <- c(1:4, NA)
x[x == 1]
[1] 1 NA
x[x %in% 1]
[1] 1
If so, using %in% is one way to avoid the problem. However, I would
have thought you'd get an error message if this were the case.
HTH .....
Peter Alspach
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Robin Jeffries
> Sent: Monday, 26 April 2010 10:26 a.m.
> To: r-help at r-project.org
> Subject: [R] Obvious reason for not looping twice?
>
> Is there an obvious reason why this won't loop to i=2 and beyond?
> There are many combinations of *st* & *vc* that don't exist in svc.
For
> example, when s=1 there's only an entry at v=1. That's fine, the
entry
> can
> stay 0.
>
> lookup.svc <-
> array(0,dim=c(length(unique(svc$st)),length(unique(svc$vc))),
> dimnames=list(unique(svc$st), unique(svc$vc)))
>
> for (i in 1:length(unique(svc$st))) {
> for (j in 1:length(unique(svc$vc))){
> lookup.svc[i,j] <- svc[svc$st == unique(svc$st)[i] & svc$vc ==
> unique(svc$vc)[j], 4]
> }}
>
>
> Thanks,
> Robin
>
> ~~~~~~~~~~~~~~~~~~~
> -Robin Jeffries
> Dr.P.H. Candidate
> UCLA School of Public Health
> rjeffries at ucla.edu
> 530-624-0428
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list