Home > Net >  interpreting the structure of a matrix
interpreting the structure of a matrix

Time:08-14

Looking at the structure of my object brca in RStudio, I see this:

Data block of R-Studio

How do I interpret the structure of brca$x? I can see x is a 2d matrix with 569 x 30 dimensions. What I have yet to understand is, what does the ..- attr(*, "dimensions")=List of 2 and .. ..$ : NULL and .. ..$ : chr[1:30] "rad... lines telling me? Similarly, y is a factor of 569, so I assume y is mapped to x[1,]' Can I reference the contents by index and/or name?

Insights appreciated...

CodePudding user response:

attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr[1:30] "radius_mean" # ...

This is telling you the dimension names of your 569 x 30 matrix. Specifically, there are no row names (hence NULL), but the 30 columns are named (e.g., the first column is named "radius_mean").

$ y: Factor w/ 2 levels "B", "M": 1 1 1 1 1 1

What it says on the tin: this is a factor with two levels, "B" and "M". The first six values are all 1, which means they’re all "B"s — the first level of your factor.

To your question about referencing — yes, you can reference the contents by index. e.g., brca$y[[1]], brca$y[3:6], or brca$y[c(2, 4, 6)]. You can also reference by value. brca$y == "B" will return a logical vector the same length as brca$y. You can then use this logical vector to reference or filter other objects: e.g., brca$x[brca$y == "B"] will return rows of brca$x corresponding to indices where brca$y is "B".

Finally, data.frame(y = brca$y, brca$x) will return a data.frame including brca$y and all columns in brca$x.

  •  Tags:  
  • r
  • Related