Why does the assignment of a 3178x93 object to another 3178x93 object remove the dimension attribute? > GT <- array(dim = c(6,nrow(InData),ncol(InSNPs))) > dim(GT) [1] 6 3178 93 > SNP1 <- InSNPs[InData[,"C1"],] > dim(SNP1) [1] 3178 93 > SNP2 <- InSNPs[InData[,"C2"],] > dim(SNP2) [1] 3178 93 > dim(pmin(SNP1,SNP2)) [1] 3178 93 > GT[1,,] <- pmin(SNP1,SNP2) > dim(GT) NULL # why?????????????????????????????????????? > GT[2,,] <- pmax(SNP1,SNP2) Error in GT[2, , ] <- pmax(SNP1, SNP2) : incorrect number of subscripts Knut M. Wittkowski, PhD,DSc ---------------------------------------------------- Sr Research Associate, The Rockefeller University Biometrician, The Rockefeller University Hospital Director, Biostatistics/Epidemiology/Research Design Center for Clinical and Translational Science (CCTS) apl. Professor, Eberhard-Karls-University, Tübingen 1230 York Ave #121B, Box 322, New York, NY 10021, US Tel: +1 (212) 327-7175, Fax: +1 (212) 327-8450 kmw@rockefeller.edu, www.rockefeller.edu/ccts/rdbs [[alternative HTML version deleted]]
>Why does the assignment of a 3178x93 object to >another 3178x93 object remove the dimension attribute?>> GT <- array(dim = c(6,nrow(InData),ncol(InSNPs)))>> dim(GT)>[1] 6 3178 93>> SNP1 <- InSNPs[InData[,"C1"],]>> dim(SNP1)>[1] 3178 93>> SNP2 <- InSNPs[InData[,"C2"],]>> dim(SNP2)>[1] 3178 93>> dim(pmin(SNP1,SNP2))>[1] 3178 93>> GT[1,,] <- pmin(SNP1,SNP2)>> dim(GT)>NULL # why??????????????????????????????????????>> GT[2,,] <- pmax(SNP1,SNP2)>Error in GT[2, , ] <- pmax(SNP1, SNP2) : incorrect number of .subscripts--------------------------------------------------- My understanding is that an array is just a list with a dimension attribute, so first note that loosing the dim attribute is not a great loss. It does not represent an inefficiency. But consider this code:> GT <- array(dim = c(6,3178, 93) )> dim(GT)[1] 6 3178 93> > > SNP1 <-as.array(matrix(0,nrow=3178,ncol=93))> dim(SNP1)[1] 3178 93> > > > GT[1,,] <- SNP1> dim(GT)[1] 6 3178 93Here what you wanted to happen happened just fine. So the question you might ask yourself is: what is different? And that leads to asking what class is the SNP1 object? If you can coerce into an array you probably can avoid the issue. Jeremiah Rounds Graduate Student Utah State University _________________________________________________________________ Get Free (PRODUCT) RED™ Emoticons, Winks and Display Pics. [[alternative HTML version deleted]]
On 5/13/2008 12:47 AM, Knut M. Wittkowski wrote:> Why does the assignment of a 3178x93 object to > another 3178x93 object remove the dimension attribute?Your example is not reproducible. When I make one that is reproducible, I don't see the error: > GT <- array(dim = c(6,3178,93)) > dim(GT) [1] 6 3178 93 > GT[1,,] <- array(dim=c(3178,93)) > dim(GT) [1] 6 3178 93 (This was done in R 2.7.0.) So I'd suggest that you try to make the example reproducible, and you'll likely discover that something else you did caused the loss of dimension. Duncan Murdoch> > > GT <- array(dim = c(6,nrow(InData),ncol(InSNPs))) > > dim(GT) > [1] 6 3178 93 > > > SNP1 <- InSNPs[InData[,"C1"],] > > dim(SNP1) > [1] 3178 93 > > > SNP2 <- InSNPs[InData[,"C2"],] > > dim(SNP2) > [1] 3178 93 > > > dim(pmin(SNP1,SNP2)) > [1] 3178 93 > > > GT[1,,] <- pmin(SNP1,SNP2) > > dim(GT) > NULL # why?????????????????????????????????????? > > > GT[2,,] <- pmax(SNP1,SNP2) > Error in GT[2, , ] <- pmax(SNP1, SNP2) : incorrect number of subscripts > > > Knut M. Wittkowski, PhD,DSc > ---------------------------------------------------- > Sr Research Associate, The Rockefeller University > Biometrician, The Rockefeller University Hospital > Director, Biostatistics/Epidemiology/Research Design > Center for Clinical and Translational Science (CCTS) > apl. Professor, Eberhard-Karls-University, T?bingen > 1230 York Ave #121B, Box 322, New York, NY 10021, US > Tel: +1 (212) 327-7175, Fax: +1 (212) 327-8450 > kmw at rockefeller.edu, www.rockefeller.edu/ccts/rdbs > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.