I'd like to know how to write an R command
which(apply(data, 2, var)==0)
... in Python.
Now I'm trying to run an R script to do a PCA.
But, pca()
accepts only non-constant columns (=Variance is not 0).
For example, only Col2 can be accepted as non-constant column in the following:
Col1 Col2 Col3
0.0 1.2 4.0
0.0 1.5 4.0
0.0 1.3 4.0
0.0 1.1 4.0
I thought I removed all constant columns.
However, I got an error:
> Error in prcomp.default(data, center = TRUE, scale = TRUE) :
cannot rescale a constant/zero column to unit variance
I googled and found this question and the R command solution:
which(apply(oopsmat, 2, var)==0)
It worked for me. The command specified which columns were still constant.
So, I removed the columns manually, and the R script did a PCA.
Now I'd like to do the same thing in Python.
How would you write this R command in Python?
#####################################################
Please don't read below, or you'll waste your time.
I leave this as an evidence that I asked a silly question:
NOTE: This R command is strange.
As I said, I already removed all constant columns from my data.
This R command tells that the variance of the following column is 0
(Excerpted from roughly 50,000 data):
:
0
0
4
0
19
0
32
61
878
4
1
13
16
14
2
4
13
:
The result of Excel's variance command VAR.P
is 231.4.
This is not even close to 0!
I don't know what's going on and I can't find such a command in Python.
So, please explain this strange behavior, too.
*I overlooked the code that removed all outliers, that's why only 0s were left.