Message-ID: <20080314205317.GD28991@localdomain>
Date: 2008-03-14T20:53:17Z
From: Gábor Csárdi
Subject: using nrow to identify one row
In-Reply-To: <753817.5484.qm@web63509.mail.re1.yahoo.com>
Try
temp[1,,drop=FALSE]
See ?"[" for the explanation.
Gabor
On Fri, Mar 14, 2008 at 04:46:10PM -0400, Gregory Gentlemen wrote:
> Hi fellow R-users,
>
> I have run into a problem when trying to identify the number of rows in a matrix. Say we have an arbitrary 5 by 5 matrix called temp:
>
> temp <- matrix(norm(25), nrow=5)
>
> The problem is that nrow(temp[1,]) returns NULL. I would like it to return 1 because in my larger program I am indexing the rows of large matrices according to another variable and I need to test when the resulting matrices have 0, 1 or more rows.
>
> Thanks in advance for any assistance.
>
> Best regards,
> Gregory Gentlemen
>
>
>
>
> ---------------------------------
>
> [[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.
--
Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM