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-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Robin Jeffries > Sent: Monday, 26 April 2010 10:26 a.m. > To: r-help@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 > rjeffr...@ucla.edu > 530-624-0428 > > [[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. ______________________________________________ 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.