| 1 |
neg2mis <- function(x,all=FALSE, |
| 2 |
exclude=NULL, |
| 3 |
select=NULL, |
| 4 |
zero=FALSE){ |
| 5 |
if(!inherits(x,"item.list")) |
| 6 |
stop("Argument 'x' must inherit from 'item.list'.") |
| 7 |
nms <- names(x) |
| 8 |
Dat <- structure([email protected],names=nms) |
| 9 |
if(all){ |
| 10 |
use <- nms |
| 11 |
} |
| 12 |
else if(!missing(exclude)){ |
| 13 |
nl <- as.list(seq_along(nms)) |
| 14 |
names(nl) <- nms |
| 15 |
dont.use <- eval(substitute(exclude), nl, parent.frame()) |
| 16 |
use <- unlist(nl[-dont.use]) |
| 17 |
} |
| 18 |
else if(!missing(select)){ |
| 19 |
nl <- as.list(seq_along(nms)) |
| 20 |
names(nl) <- nms |
| 21 |
use <- eval(substitute(select), nl, parent.frame()) |
| 22 |
use <- unlist(nl[use]) |
| 23 |
} |
| 24 |
else { |
| 25 |
stop("one of the arguments 'all', 'exclude', or 'select' shoud be supplied") |
| 26 |
} |
| 27 |
Dat[use] <- lapply(Dat[use],neg2mis_1,zero=zero) |
| 28 |
[email protected] <- unname(Dat) |
| 29 |
x |
| 30 |
} |
| 31 |
|
| 32 |
neg2mis_1 <- function(x,zero=zero){ |
| 33 |
if(length(value.filter(x))) return(x) |
| 34 |
else { |
| 35 |
if(zero) |
| 36 |
missing.values(x) <- list(range=c(-Inf,0)) |
| 37 |
else |
| 38 |
valid.range(x) <- c(0,Inf) |
| 39 |
return(x) |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|