Re: [R] why the dim gave me different results

From: RICHARD M. HEIBERGER <rmh_at_temple.edu>
Date: Wed, 02 Jun 2010 18:00:18 -0400

This is a guess since you didn't say where it comes from. It looks like a data.frame where some rows were deleted. Also, note that the column names in your example are sorted alphabetically instead of numerically. This example shows one way to get that behavior.

Rich

> tmp <- data.frame(matrix(1:24, 6, 4, dimnames=list(1:6, c(1,2,11,12))))
> tmp

  X1 X2 X11 X12
1 1 7 13 19
2 2 8 14 20
3 3 9 15 21
4 4 10 16 22
5 5 11 17 23
6 6 12 18 24
> dimnames(tmp)[[2]] <- sort(dimnames(tmp)[[2]])
> tmp

  X1 X11 X12 X2
1 1 7 13 19
2 2 8 14 20
3 3 9 15 21
4 4 10 16 22
5 5 11 17 23
6 6 12 18 24
> tmp[c(2,5,3),]

  X1 X11 X12 X2
2 2 8 14 20
5 5 11 17 23
3 3 9 15 21
>

On Wed, Jun 2, 2010 at 5:47 PM, Changbin Du <changbind_at_gmail.com> wrote:

> > dim(tmp)
> [1] 576 12
> > tmp
>
> 1 10 11 12 13 2 3 4 5 6 7 9
> 1 0 0 0 0 0 0 0 12 0 0 0 0
> 2 0 0 0 0 0 0 0 15 0 0 0 0
>

        [[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. Received on Wed 02 Jun 2010 - 22:06:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Jun 2010 - 22:10:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive