[R] two questions for R beginners
petr.pikal at precheza.cz
Mon Mar 1 12:09:51 CET 2010
r-help-bounces at r-project.org napsal dne 01.03.2010 11:26:40:
> On Mon, 1 Mar 2010 11:02:59 +0100 Karl Ove Hufthammer <karl at huftis.org>
> > > * What were your biggest misconceptions or
> > > stumbling blocks to getting up and running
> > > with R?
> > Also I found it quite confusing that
> One more thing that still trips me up sometimes. '$' works on data
> frames but not on matrices (with dimnames/colnames). Even though the two
> objects *look* exactly the same, '$' on one of them works while '$' on
> the other gives a *very* confusing error message. Example:
> Some functions output matrices where you would expect them to output
> data frames, and then this problem occurs. (Is there a reason why '$'
> could/should not be made to 'work' on matrices too?)
I understand that 2 dimensional rectangular matrix looks quite similar to
data frame however it is only a vector with dimensions. As such it can
have items of only one type (numeric, character, ...). And you can easily
change dimensions of matrix.
dim(matrix) <- c(2,6)
dim(matrix) <- c(2,2,3)
So rectangular structure of printed matrix is a kind of coincidence only,
whereas rectangular structure of data frame is its main feature.
> Karl Ove Hufthammer
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help