Error: Incorrect number of dimensions in R

Elle, try this if you want to exclude the records with NA.

library(psych) 
data <- sat.act[complete.cases(sat.act), ]
prcomp(data)

Standard deviations:
[1] 146.8300134  68.2543504   9.5430803   3.6666452   1.1715551   0.4647055

Rotation:
                    PC1           PC2           PC3          PC4           PC5
gender     0.0003401435 -0.0012020541  0.0010970565  0.005788342 -0.0591625722
education -0.0004299901 -0.0002918314 -0.0850528466  0.024064095 -0.9943380906
age        0.0027020833  0.0014188342 -0.9929359565 -0.084983862  0.0824906340
ACT       -0.0208448308  0.0016963799 -0.0827031922  0.995852246  0.0314096125
SATV      -0.6956211490 -0.7182796666 -0.0017374908 -0.013494765  0.0003648618
SATQ      -0.7181010432  0.6957498829  0.0003989952 -0.016166443 -0.0003874180
                PC6
gender    -0.9982301944
education  0.0589781669
age       -0.0064738244
ACT        0.0038129483
SATV       0.0005261265
SATQ      -0.0011528452

Or if you want to force NA to 0

data <- sat.act
data[is.na(data)] <- 0
prcomp(data)

Standard deviations:
[1] 159.4488983  85.1587086   9.5463091   3.7961644   1.1814762   0.4653497

Rotation:
                     PC1           PC2           PC3          PC4           PC5
gender     0.0003915730 -7.364935e-04  0.0008193646  0.002717142 -0.0591610356
education -0.0004932616 -9.314099e-05 -0.0837084272  0.019199014 -0.9945610838
age        0.0012746540  4.606768e-03 -0.9933615141 -0.080624581  0.0817016560
ACT       -0.0172578373 -1.064616e-02 -0.0788111515  0.996345023  0.0259420620
SATV      -0.5500283967 -8.349310e-01 -0.0030404778 -0.018696325  0.0002655931
SATQ      -0.8349664116  5.502319e-01  0.0021652104 -0.008410428 -0.0000266278
                    PC6
gender    -0.9982440693
education  0.0589261882
age       -0.0058797665
ACT        0.0011109106
SATV       0.0003311219
SATQ      -0.0007530176

Leave a Comment