[R] length of the object is not a multiple of... [was: Re: hello]

Petr Klasterecky klaster at karlin.mff.cuni.cz
Wed May 2 11:46:55 CEST 2007



elyakhlifi mustapha napsal(a):
> hello,
> I have a problem with a R program I don't understand my errors
> my program looks like this
> 
>> for(i in LE) {
> +    for(j in LEC[[i]]) {
> +                for(k in LR) {
> +                         donRep[[k]] <- subset(don2, Id_Essai == 1006961 & Id_Cara == j & Id_Rep == k  & Id_Geno != 65125, select = Val_O)
> +                         M[[j]] <- matrix(rep(1, 3*length(donRep[[1]][,1])), nrow =length(donRep[[1]][,1]), ncol = 3)
> +                        for(k in LR) {
> +              M[[j]][,k] <- as.numeric(as.character(donRep[[k]][,1]))
> +                }
> +                         }
> +                print(M[[j]])
> +                if (subset(donParCara, Id_Cara == j , select = Ana_C) == "AV")
> +               {print(cor(M[[j]], method = "pearson"))}  else{print(cor(M[[j]], method = "spearman"))}
> + }
> +       }
> Erreur dans M[[j]][, k] <- as.numeric(as.character(donRep[[k]][, 1])) : 
>         le nombre d'objets ŕ remplacer n'est pas multiple de la taille du remplacement
> 
> 
> 
> and sometimes it run good but sometimes there are errors I don't understand why. Can you help me please?

No we can't since we cannot reproduce your program. The error message 
says you are trying to assign a longer/shorter vector into a matrix. Add 
some print statements into your code and check how M[[j]] and 
donRep[[k]][,1] look like in each step of the loop.

And next time, read the posting guide and give a meaningfull subject and 
a reproducible example.

Petr

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic



More information about the R-help mailing list