[R] dimnames(x) <- dn error

Joshua Wiley jwiley.psych at gmail.com
Fri Jun 25 04:06:18 CEST 2010


Hello Ayesha,

What would you like the rownames to be?  Your problem is that
dim(distF)[1] will return the length of the 1st dimension; this is a
single number.  This code shows what happens and gives you some
alternatives.

temp.data <- matrix(1:9, ncol=3)
temp.data
dim(temp.data)[1]

## Possible Alternative 1
## closest to what you had
rownames(temp.data) <- paste("A", 1:dim(distF)[1])
rownames(temp.data)

## Possible Alternative 2
## no space
rownames(temp.data) <- paste("A", 1:dim(distF)[1])
rownames(temp.data)

## Possible Alternative 3
##letters vary
rownames(temp.data) <- paste(LETTERS[1:dim(distF)[1]], 1, sep="")
rownames(temp.data)

Cheers,

Josh



On Thu, Jun 24, 2010 at 6:13 PM, Ayesha Khan
<ayesha.diamondash at gmail.com> wrote:
> Hi ,
> I want to assign names to the rows in my matrix so that when I use the
> 'agnes'  function from R cluster package , the dendogram that is produced
> represents the rows of the matrix. This way I would know what elements in
> the matrix are clustered together. But when I do the following,
> rownames(distF) <- paste("A",dim(distF)[1])
>
> it gives the following error;
> Error in dimnames(x) <- dn :
>  length of 'dimnames' [1] not equal to array extent
>
> What am I doing wrong? Any help is most appreciated
>
> --
> Ayesha Khan
>
> MS Bioengineering
> Dept. of Bioengineering
> Rice University, TX
>
>        [[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.
>



-- 
Joshua Wiley
Ph.D. Student
Health Psychology
University of California, Los Angeles



More information about the R-help mailing list