R : subscript out of bounds
Edit : Problème résolu grâce à un autre Forum
Bonjour,
J'espère être dans le bon forum
Je dois,pour un projet réaliser une carte de Kohonen 4*4.
Cependant, j'obtiens l'erreur
Code:
1 2
| Error in win_index[1, ] : subscript out of bounds
In addition: There were 16 warnings (use warnings() to see them) |
Après avoir testé mon code, je suppose que c'est la fonction lapply (ligne 76 ) qui ne
s'éxecute pas bien car la matrice ainsi créée ne contient que des NA.
Et donc comme cette matrice est utilisée par la suite, le résultat n'est pas coorrect car
les NA se retrouve tout au long du programme.
code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #############################################
##Function for distance calculation (RMSDA)##
#############################################
RMSDA<-function(data_phipsi,Kohonen_matrix)
{
difference<-data_phipsi-Kohonen_matrix
for(j in 1:length(difference)){
if (difference[j]< -180) {difference[j]=difference[j]+360}
if (difference[j]> +180) {difference[j]=difference[j]-360}
}
distance=mean(sqrt(difference^2)) #http://rug.mnhn.fr/seewave/HTML/MAN/rms.html
return(distance)
}
##############################
## Program ###
##############################
for(step in 1:iteration)
{
data_phipsi<-data_phipsi[sample(nrow(data_phipsi)),] # Sample vectors of training (samples of lines of the dataframe)
print(step) #Visualize where we are in loops
for(k_row in 1:nrow(data_phipsi))
{
#Update learn_rate and radius at each row of each iteration
learn_rate<-learning(initial_rate,((step-1)*nrow(data_phipsi))+k_row,data_phipsi)
learn_radius<-learning(initial_radius,((step-1)*nrow(data_phipsi))+k_row,data_phipsi)
#Find distance between each vectors of angles of Kohonen Map and the training vector
phipsi_RMSDA<-lapply(random_list, RMSDA, data_phipsi=data_phipsi[k_row,])
}
} |
Comment est-il possible de régler cette erreur de lapply ?
Merci