[R] keeping dim() for array

Federico Calboli f.calboli at imperial.ac.uk
Tue Nov 21 13:20:48 CET 2006


Hi All,

I noticed the following:

pip = array(1:6, dim = c(3,2))
dim(pip)
[1] 3 2

pup = pip[1,]
dim(pup)
NULL

I bet there is a *good* reason why one row of an array is *dimensionless*, but 
it's highly inconvenient for my purpose, i.e. to use apply() after an array goes 
through a number of logical steps and is redimensioned, sometimes to one single row.

How do I keep dim(pup) to 1 2?

Since pup is at the end of a number of if(), it does not necessarily end up as 
one row only, so t(as.matrix(pup)) is the *wrong* answer.

Best,

Federico

-- 
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602     Fax (+44) 020 7594 3193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com



More information about the R-help mailing list