1# File src/library/stats/R/contrast.R 2# Part of the R package, http://www.R-project.org 3# 4# Copyright (C) 1995-2012 The R Core Team 5# 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 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# A copy of the GNU General Public License is available at 17# http://www.r-project.org/Licenses/ 18 19## a fast version of diag(n, .) / sparse-Diagonal() + dimnames 20## Originally .Diag in stats:contrast.R 21 22.RDiag <- function (nms, sparse) { 23 n <- as.integer(length(nms)) 24 d <- c(n, n) 25 dn <- list(nms, nms) 26 # if (sparse) { 27 # requireNamespace("Matrix", quietly = TRUE) 28 # new("ddiMatrix", diag = "U", Dim = d, Dimnames = dn) 29 # } 30 # else 31 array(c(rep.int(c(1, numeric(n)), n - 1L), 1), d, dn) 32}