s-news
[Top] [All Lists]

error using "by"

To: s-news@lists.biostat.wustl.edu
Subject: error using "by"
From: susan@stats.ucl.ac.uk
Date: Wed, 16 Feb 2005 18:35:40 -0000 (GMT)
Importance: Normal
User-agent: SquirrelMail/1.4.3a
Dear Colleagues

I am having some difficuly with the by function. In the function DtW below
I get the correct answer if p=1 but the error message if p=2. The problem
seems to occur after Dt had been done. Any help would be greatly
appreciated and I apologies in advance if it's something trivial that I
missed.

Thank you again
susan

DtW <- function(data.mat, W, p)
{
        D2 <- data.mat[, 5]
        cls <- length(D2)
        D1 <- matrix(1, cls, 1)
        D <- D1
        if(p == 2) {
                D <- data.frame(D1, D2)
        }
        Dt <- t(D)
        print(Dt)
        DtW <- Dt %*% W
        DtWD <- DtW %*% D
        print(DtWD)
        DtWD

#gen data
tempdat1 <- simdat(2, 3, 0, "exch", 0.5)
print(tempdat1)
     clid clsize visit        yij grp
[1,]  300      3     1 -0.4788661   0
[2,]  300      3     3 -0.3704168   0
[3,]  300      3     6 -1.8812922   0
[4,]  301      3     1 -0.4165800   1
[5,]  301      3     3  0.9933311   1
[6,]  301      3     4 -0.6556154   1
W3 <- matrix(2, 3, 3)
testdtw <- by(tempdat1, tempdat1[, 1], DtW, W = W3, p
         = 2)
   1 2 3
D1 1 1 1
D2 0 0 0
Error in as.double: Cannot coerce mode list to double: .Data = list(..






<Prev in Thread] Current Thread [Next in Thread>