View | Details | Raw Unified | Return to bug 16895 | Differences between
and this patch

Collapse All | Expand All

(-)table/factor.R (-3 / +4 lines)
Lines 1-7 Link Here
1
#  File src/library/base/R/factor.R
1
#  File src/library/base/R/factor.R
2
#  Part of the R package, https://www.R-project.org
2
#  Part of the R package, https://www.R-project.org
3
#
3
#
4
#  Copyright (C) 1995-2015 The R Core Team
4
#  Copyright (C) 1995-2016 The R Core Team
5
#
5
#
6
#  This program is free software; you can redistribute it and/or modify
6
#  This program is free software; you can redistribute it and/or modify
7
#  it under the terms of the GNU General Public License as published by
7
#  it under the terms of the GNU General Public License as published by
Lines 341-348 Link Here
341
addNA <- function(x, ifany=FALSE)
341
addNA <- function(x, ifany=FALSE)
342
{
342
{
343
    if (!is.factor(x)) x <- factor(x)
343
    if (!is.factor(x)) x <- factor(x)
344
    if (ifany & !anyNA(x)) return(x)
344
    if (ifany && !anyNA(x)) return(x)
345
    ll <- levels(x)
345
    ll <- levels(x)
346
    if (!anyNA(ll)) ll <- c(ll, NA)
346
    if (anyNA(ll)) return(x)
347
    ll <- c(ll, NA)
347
    factor(x, levels=ll, exclude=NULL)
348
    factor(x, levels=ll, exclude=NULL)
348
}
349
}
(-)table/table.R (-3 / +5 lines)
Lines 1-7 Link Here
1
#  File src/library/base/R/table.R
1
#  File src/library/base/R/table.R
2
#  Part of the R package, https://www.R-project.org
2
#  Part of the R package, https://www.R-project.org
3
#
3
#
4
#  Copyright (C) 1995-2015 The R Core Team
4
#  Copyright (C) 1995-2016 The R Core Team
5
#
5
#
6
#  This program is free software; you can redistribute it and/or modify
6
#  This program is free software; you can redistribute it and/or modify
7
#  it under the terms of the GNU General Public License as published by
7
#  it under the terms of the GNU General Public License as published by
Lines 81-89 Link Here
81
                    else {
81
                    else {
82
                        if (useNA != "no")
82
                        if (useNA != "no")
83
                            a <- addNA(a, ifany = (useNA == "ifany"))
83
                            a <- addNA(a, ifany = (useNA == "ifany"))
84
                        ll <- levels(a)
84
                        nl <- length(ll <- levels(a))
85
                        a <- factor(a, levels = ll[!(ll %in% exclude)],
85
                        if (length(ll <- ll[!(ll %in% exclude)]) != nl)
86
                            a <- factor(a, levels = ll,
86
                               exclude = if (useNA == "no") NA)
87
                               exclude = if (useNA == "no") NA)
88
                        a
87
                    }
89
                    }
88
                }
90
                }
89
            }
91
            }

Return to bug 16895