Hey eveyone! I hope someone can help wiht this question. I have a matirux of all zeros and ones and I would like to indentify all unique patterns in the rows andthe number of times the pattern occurs. I changed all zeros to NA tried to use prelim.norm to identify all patterns of missing data in the rows. I got the message Warning message: NAs introduced by coercion Any ideas of how to get this to work? Or are there any way to indentify all the unique patterns in a huge matrix? ( 10000 x 71) Thanks for any suggestions!! Elizabeth Lawson --------------------------------- [[alternative HTML version deleted]]
Elizabeth Lawson <lizzylaws at yahoo.com> writes:> Hey eveyone! I hope someone can help wiht this question. I have a matirux of all zeros and ones and I would like to indentify all unique patterns in the rows andthe number of times the pattern occurs. I changed all zeros to NA tried to use prelim.norm to identify all patterns of missing data in the rows. I got the message > > Warning message: > NAs introduced by coercion > > Any ideas of how to get this to work? Or are there any way to indentify all the unique patterns in a huge matrix? ( 10000 x 71) > > Thanks for any suggestions!!unique() has a matrix method. For tabulation, you might consider a modification of unique.matrix. Or maybe aggregate() or by() will do the trick. -- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Others will certainly suggest more efficient ways to do this, but here is an inefficient approach: > X <- matrix(sample(c(0,1), 10000*3, replace=TRUE), ncol=3) > t(t(table(apply(X, 1, paste, collapse="")))) [,1] 000 1197 001 1238 010 1245 011 1230 100 1331 101 1259 110 1247 111 1253 You are getting a warning and not an error from prelim.norm(), and the answer it gives seems to match the approach above. > library(norm) > X <- apply(X, 2, function(x){replace(x, x == 0, NA)}) > prelim.norm(X)$r [,1] [,2] [,3] 1253 1 1 1 1230 0 1 1 1259 1 0 1 1238 0 0 1 1247 1 1 0 1245 0 1 0 1331 1 0 0 1197 0 0 0 hope this helps, Chuck Elizabeth Lawson wrote:> Hey eveyone! I hope someone can help wiht this question. I have a matirux of all zeros and ones and I would like to indentify all unique patterns in the rows andthe number of times the pattern occurs. I changed all zeros to NA tried to use prelim.norm to identify all patterns of missing data in the rows. I got the message > > Warning message: > NAs introduced by coercion > > Any ideas of how to get this to work? Or are there any way to indentify all the unique patterns in a huge matrix? ( 10000 x 71) > > Thanks for any suggestions!! > > Elizabeth Lawson > > > --------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
On 01-Feb-06 Elizabeth Lawson wrote:> Hey eveyone! I hope someone can help wiht this question. I have a > matirux of all zeros and ones and I would like to indentify all unique > patterns in the rows andthe number of times the pattern occurs. I > changed all zeros to NA tried to use prelim.norm to identify all > patterns of missing data in the rows. I got the message > > Warning message: > NAs introduced by coercion > > Any ideas of how to get this to work? Or are there any way to > indentify all the unique patterns in a huge matrix? ( 10000 x 71) > > Thanks for any suggestions!! > > Elizabeth LawsonI think Chuck Celand has pretty well answered it: Don't worry about the warning, since I'm pretty sure it is generated when prelim.norm is calculating something else (e.g. the covariance matrix) and it is not related to generating prelim.norm(X)$r which is the list of patterns and the numbers of times they occur. Best wsihes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 01-Feb-06 Time: 15:44:34 ------------------------------ XFMail ------------------------------