[R] Stop Warnings for Invalid Factor Level, NAs generated?
khobson@fd9ns01.okladot.state.ok.us
khobson at fd9ns01.okladot.state.ok.us
Thu Jun 23 15:09:11 CEST 2005
How can I stop the following warning from occuring?
invalid factor level, NAs generated in: "[<-.factor"(`*tmp*`, iseq, value =
structure(1, .Label = "12", class = "factor"))
The Label messages are for "5", "8", "12" and "46". I want the NAs to be
generated as needed.
Is this causing R to slow down by generating the warning messages? There
are over 50. I loop through up to 10 datasets and append one row from each
to create a summary dataset.
The full code and data is too long to post. The snippet below might
explain what I'm doing somewhat. I'll work up some sample data and code if
no solutions are found.
...snip
> # Get info on first and last pair sets and lab names in last pair
> nlabs <- labdata[["LABNUMBER"]] #e.g. 1, 2, 5, 6, ...
> nolabs <- length(nlabs) #Total number of labs in last pair of labdata
> #dpdata <- labdata[which(labdata[["LABNUMBER"]] == 13),] #Dummy paired
data row
> dpdata <- rbind(labdata[0,], NA)
> pdata <- dpdata
> # Loop through pairs of labdata to build pdata for pairs (last 10 years
or less)
> k=0
> for(j in nlabs){
+ for(i in ifpair:ilpair){
+ k <- k + 1 #Counter for number of pairs. Start at 1.
+ setwd(dirs[i]); load("labdata.Rdata") #No trailing "/" in wd
+ setwd(cdir) #Go back to original ESN pair (last pair's folder in
analysis)
+ tpdata <- labdata[which(labdata[["LABNUMBER"]] == j),]
+ if(NROW(tpdata) == 0){
+ tpdata <- dpdata
+ tpdata[which(names(labdata) == "LABNUMBER")] <- j
+ tpdata[which(names(labdata) == "ESN")] <-
ESN-((ilpair-ifpair)+1-k)*2
+ tpdata[which(names(labdata) == "ESNm1")] <-
ESN-((ilpair-ifpair)+1-k)*2-1
+ }
+ #pdata[nrow(pdata)+1,names(tpdata)] <- NA
+ pdata[nrow(pdata)+1,names(tpdata)] <- tpdata
+ }
+ }
There were 50 or more warnings (use warnings() to see the first 50)
...snip
mailto:khobson at odot.org
Kenneth Ray Hobson, P.E.
Oklahoma DOT - QA & IAS Manager
200 N.E. 21st Street
Oklahoma City, OK 73105-3204
(405) 522-4985, (405) 522-0552 fax
Visit our website at:
http://www.okladot.state.ok.us/materials/materials.htm
More information about the R-help
mailing list