[R] Is it possible to define another kind of NA

Marc Girondot marc_grt at yahoo.fr
Thu Nov 13 12:08:03 CET 2014


Le 13/11/2014 01:26, MacQueen, Don a écrit :
> Along the lines of what Bert Gunter said, the ideal way to represent <LDL
> results depends on the functions used later to analyze them. I deal with
> such data on a daily basis and have never found it necessary to
> incorporate that information in the same variable as the results. What
> would you do if data were censored at both ends, both low and high?
>
> Anyway, the functions I use mostly incorporate that information in a
> second variable, a ³detection indicator² variable, and that¹s what I do.
>
> -Don
>
I agree that LDL is a special case of what could be named ODL (Out of 
detection limit).
To answer to Bert Gunter, indeed if LDL (or ODL) values are changed into 
NA, the results will be biased. That's why I would like to introduce 
another category. I don't plan to just transform them as NA.

But thinking again about this problem, a LDL must be always associated 
with one value (or two in the case of ODL) that indicates the detection 
limit. In a dataset, all values have not necessarily the same limit 
depending on the experimental conditions.
The best solution that I find is to use attributes to indicate the 
limits. A NA attribute for a NA value will be treated as a "true" NA.
For exemple:

 > values <- c(NA, 29, 30, NA, 3)
 > attributes(values) <- list(ODL=c(NA, "[10, 40]", "[0, 40]", "[0, 
40]", "[0, 40]"))
 > values
[1] NA 29 30 NA  3
attr(,"ODL")
[1] NA         "[10, 40]" "[0, 40]"  "[0, 40]"  "[0, 40]"
 > values[3]
[1] 30
 > attributes(values)$ODL[3]
[1] "[0, 40]"
 > values[1]
[1] NA
 > attributes(values)$ODL[1]
[1] NA

The attributes are retained in data.frame. So it seems to be a good 
solution.

 > essai <- data.frame(c1=values)
 > essai
   c1
1 NA
2 29
3 30
4 NA
5  3
 > essai$c1
[1] NA 29 30 NA  3
attr(,"ODL")
[1] NA         "[10, 40]" "[0, 40]"  "[0, 40]"  "[0, 40]"

Thanks to the list members,

Marc



More information about the R-help mailing list