makansij
makansij

Reputation: 9865

How to find the real datatype of a variable in R?

Datatypes in R have always confused me, and I'm sorry if this is an elementary question. I know that the $loadings attribute in R is supposed to be a matrix. even the documentation says that if you type ?loadings: it says it is the matrix of variable loadings.

arrests_pca <- princomp(USArrests, cor=TRUE)
typeof(arrests_pca$loadings)

....returns

[1] "double"

...and so I tried to find the class:

> class(arrests_pca$loadings)
[1] "loadings"

Upvotes: 1

Views: 1468

Answers (2)

Sowmya S. Manian
Sowmya S. Manian

Reputation: 3833

Use mode()

mode(arrests_pca$loadings)

Upvotes: 0

user2554330
user2554330

Reputation: 44788

Use str(arrests_pca$loadings). It returns

 loadings [1:4, 1:4] -0.536 -0.583 -0.278 -0.543 0.418 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:4] "Murder" "Assault" "UrbanPop" "Rape"
  ..$ : chr [1:4] "Comp.1" "Comp.2" "Comp.3" "Comp.4"

You can see on the first line that it's a 4x4 matrix.

Upvotes: 2

Related Questions