[R] keeping dim() for array

Roger Bivand Roger.Bivand at nhh.no
Tue Nov 21 13:51:21 CET 2006


On Tue, 21 Nov 2006, Federico Calboli wrote:

> 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?

> pup = pip[1,,drop=FALSE]
> dim(pup)
[1] 1 2

R FAQ 7.5, by the way.

> 
> 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
> 
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-help mailing list