svd(x, nu = 0, nv = k) 错误:'x' 中存在无限值或缺失值。矩阵中没有 NA 或 Inf 值
Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'. There are no NA or Inf values in matrix
我检查了矩阵中的 NA、Inf 和 -Inf。没有出现。发生了什么事?
head(peaks.new)
X99 X111 X127 X191 X196 X273 X347 X357 X372 X430 X542 X601 X676 X688 X730
[1,] 0.5804457 1.144064 1.060764 0.3957671 0.4605744 1.395375 0.3997679 0.4058198 0.6135423 1.024926 0.3185467 0.4280903 0.4200074 0.4150762 1.026295
[2,] 0.6738807 1.228152 1.199513 0.4588390 0.5470579 1.383542 0.4491294 0.4576340 0.7606879 1.188590 0.3476853 0.4771873 0.5021612 0.4848465 1.165312
[3,] 0.6315261 1.235551 1.234193 0.4415364 0.5230350 1.514145 0.4512593 0.4589265 0.7238682 1.180188 0.3389439 0.4703305 0.4733625 0.4622625 1.175494
[4,] 0.6482746 1.240872 1.270660 0.5258102 0.5381634 1.430304 0.4888256 0.4987946 0.8740429 1.189461 0.3790521 0.5155980 0.4893849 0.4897720 1.090612
[5,] 0.6110295 1.215108 1.162420 0.4374122 0.4988751 1.435029 0.4320153 0.4360902 0.7144469 1.148086 0.3276657 0.4432349 0.4520939 0.4402073 1.129200
[6,] 0.7070189 1.344910 1.254874 0.4893428 0.5730396 1.708531 0.4627560 0.4797072 0.7752893 1.229642 0.3612133 0.4825547 0.5037152 0.4896373 1.267938
pca.peaks <- prcomp(t(peaks.new), scale=T, retx=T, center=T)
Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'
which(peaks.new==0)
integer(0)
> which(peaks.new==Inf)
integer(0)
> which(peaks.new==-Inf)
integer(0)
> which(peaks.new==NA)
integer(0)
NA
很棘手。考虑一下:
> a = c(1, NA, 2)
> which(a == NA)
integer(0)
> a == NA
[1] NA NA NA
与 NA 的相等性检查将导致 NA。检查 NA 的正确方法是使用 is.na()
函数:
> is.na(a)
[1] FALSE TRUE FALSE
对于 Inf
的情况还有 is.infinite()
,尽管在那种情况下直接比较有效(例如 (1/0) == Inf
产生 TRUE
)。
我检查了矩阵中的 NA、Inf 和 -Inf。没有出现。发生了什么事?
head(peaks.new)
X99 X111 X127 X191 X196 X273 X347 X357 X372 X430 X542 X601 X676 X688 X730
[1,] 0.5804457 1.144064 1.060764 0.3957671 0.4605744 1.395375 0.3997679 0.4058198 0.6135423 1.024926 0.3185467 0.4280903 0.4200074 0.4150762 1.026295
[2,] 0.6738807 1.228152 1.199513 0.4588390 0.5470579 1.383542 0.4491294 0.4576340 0.7606879 1.188590 0.3476853 0.4771873 0.5021612 0.4848465 1.165312
[3,] 0.6315261 1.235551 1.234193 0.4415364 0.5230350 1.514145 0.4512593 0.4589265 0.7238682 1.180188 0.3389439 0.4703305 0.4733625 0.4622625 1.175494
[4,] 0.6482746 1.240872 1.270660 0.5258102 0.5381634 1.430304 0.4888256 0.4987946 0.8740429 1.189461 0.3790521 0.5155980 0.4893849 0.4897720 1.090612
[5,] 0.6110295 1.215108 1.162420 0.4374122 0.4988751 1.435029 0.4320153 0.4360902 0.7144469 1.148086 0.3276657 0.4432349 0.4520939 0.4402073 1.129200
[6,] 0.7070189 1.344910 1.254874 0.4893428 0.5730396 1.708531 0.4627560 0.4797072 0.7752893 1.229642 0.3612133 0.4825547 0.5037152 0.4896373 1.267938
pca.peaks <- prcomp(t(peaks.new), scale=T, retx=T, center=T)
Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'
which(peaks.new==0)
integer(0)
> which(peaks.new==Inf)
integer(0)
> which(peaks.new==-Inf)
integer(0)
> which(peaks.new==NA)
integer(0)
NA
很棘手。考虑一下:
> a = c(1, NA, 2)
> which(a == NA)
integer(0)
> a == NA
[1] NA NA NA
与 NA 的相等性检查将导致 NA。检查 NA 的正确方法是使用 is.na()
函数:
> is.na(a)
[1] FALSE TRUE FALSE
对于 Inf
的情况还有 is.infinite()
,尽管在那种情况下直接比较有效(例如 (1/0) == Inf
产生 TRUE
)。