m = matrix(1:4, 2) apply(m, 1, cat, '\n') # 1 2 # 3 4 # NULL why the null? vQ
Hi! Wacek Kusnierczyk wrote:> m = matrix(1:4, 2) > > apply(m, 1, cat, '\n') > # 1 2 > # 3 4 > # NULL > > why the null?Could it be the return value of 'cat'. See ?cat, where: ---snip --- Value None (invisible NULL). ---snip --- Kind regrads, Kimmo
Wacek Kusnierczyk wrote:> m = matrix(1:4, 2) > > apply(m, 1, cat, '\n') > # 1 2 > # 3 4 > # NULL > > why the null?It comes from unlist()ing a list of NULLs, which in turn are the return values of cat(). It is arguably a design-buglet not to return list(NULL, NULL), but the internal logic is to unlist() unless the first element is.recursive (and NULL is not) or the return values have different length() (and all are zero). It _is_, however, in accordance with the documentation (see the Value: section): -- 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
> out <- apply(m, 1, cat, '\n')1 3 2 4> outNULL On Wed, May 13, 2009 at 5:23 AM, Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:> ? ?m = matrix(1:4, 2) > > ? ?apply(m, 1, cat, '\n') > ? ?# 1 2 > ? ?# 3 4 > ? ?# NULL > > why the null? > > vQ > > ______________________________________________ > 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. >